Longest Substring Without Repeating Characters - Leetcode 3 - Sliding Window (Python)

  Рет қаралды 15,613

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 29
@GregHogg
@GregHogg 5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@vaibhavchetri8819
@vaibhavchetri8819 2 ай бұрын
Best Explanation. Its Crystal Clear
@AvinashKumar-d1i1p
@AvinashKumar-d1i1p Ай бұрын
Best explaINATION ON THIS TOPIC ON YT..
@middle-agedclimber
@middle-agedclimber 6 ай бұрын
Best solution I've seen. Thanks
@HelicopterRidesForCommunists
@HelicopterRidesForCommunists 5 ай бұрын
lol thats literally what I said. Best explanation too.
@HussainAli-hn2ef
@HussainAli-hn2ef 3 ай бұрын
great explanation!
@pumpkinp6906
@pumpkinp6906 9 ай бұрын
Great explanation ! It would be great if you would share the leetcode problem link in description so that we can implement ourselves after learning
@HelicopterRidesForCommunists
@HelicopterRidesForCommunists 5 ай бұрын
Best solution Ive seen. Nice!
@Jay-zr8kx
@Jay-zr8kx Ай бұрын
instead of using set, using key value pair object, to track the last index a character is found so that {a:0, b:1, c:2}, then when a second a is found if we update the a index to {a:3, b:1, c:2} then left pointer to original a index +1, are we able to save the extra looping until finding valid substring?
@DamosyTheFreckle
@DamosyTheFreckle 6 ай бұрын
Good explanation, thank you!
@ryan.aquino
@ryan.aquino 2 ай бұрын
Get the length of the set instead when comparing. Much easier to think intuitively
@kashinathpatekar9870
@kashinathpatekar9870 9 ай бұрын
Technically the size of the set will be limited by the character set used, so can we call it O(1) space?
@GregHogg
@GregHogg 9 ай бұрын
Oops did I say O(n) space? You're completely correct, yes!
@kashinathpatekar9870
@kashinathpatekar9870 9 ай бұрын
Thanks for clarifying!
@foudilbenouci482
@foudilbenouci482 6 ай бұрын
more exactly O(n/c) where c is the capacity of the character set used and n the size of the string
@shashank5175
@shashank5175 3 ай бұрын
@@foudilbenouci482 O(n/c) could be reduced to O(n) or am I wrong cause I thought you can reduce multiplication and division but can reduce addition and subtraction
@pravuchaudhary3904
@pravuchaudhary3904 3 ай бұрын
I have two questions: 1. insted of while loop , why not use if...else 2. after while loop: instead of removing and updating the char in sett, why not add string in sett first and start update "longest"
@rajarshibiswas9424
@rajarshibiswas9424 6 ай бұрын
i don't know why the code I have written is exactly same instead of set I used hash map should i have used hash set?? is hash map is the main cause of output limit exceeded??
@yuasufhelal7181
@yuasufhelal7181 5 ай бұрын
It's a basic one but please I have question what if we use if s(r) in seen willl it be completely wrong but by what sense. Since you were using while.
@ParaSteve1985
@ParaSteve1985 9 ай бұрын
Hi there, are you still available for 1o1 trainings sessions?
@GregHogg
@GregHogg 9 ай бұрын
Yes, please email greg.hogg1@outlook.com
@ParaSteve1985
@ParaSteve1985 9 ай бұрын
@@GregHogg done, waiting for your reply.
@sumeethraikar711
@sumeethraikar711 3 ай бұрын
set doesnt preserve insertion order. so how removing of elements is working here.?
@freshedits8408
@freshedits8408 3 ай бұрын
They are removing based on the actual character, but not with an index so it is working.
@salxs9664
@salxs9664 Ай бұрын
@@freshedits8408 Can you explain why it's not an index because I see sett.remove(s[l]) and then l += 1 so shouldn't it be removing sett at index 0 and then moving up? This is something that I am confused by as well. When you add items to the set the first item you add doesn't necessarily stay at index 0
@freshedits8408
@freshedits8408 Ай бұрын
@@salxs9664 no, here s means string so we are removing a first index of the string Suppose if s[l] means "a" which is the first index in the string and we are removing "a" from the set like set.remove("a"). If the char already exists then we are removing it. Every time we remove, we are changing the starting index
@salxs9664
@salxs9664 Ай бұрын
@@freshedits8408 Thank you that explains it!
@ohskynyrdlynyrd
@ohskynyrdlynyrd 4 сағат бұрын
"When window is valid we move R, when it's invalid we move L". Had to type it to memorize
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Longest Repeating Character Replacement - Leetcode 424 - Python
20:44
Number of Islands - Leetcode 200 - Graphs (Python)
11:01
Greg Hogg
Рет қаралды 12 М.
Climbing Stairs - Leetcode 70 - Dynamic Programming (Python)
10:54
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 328 М.
Leetcode 3. Longest Substring Without Repeating Characters
15:49
Code with Alisha
Рет қаралды 74 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН