Sliding Window Algorithm Explained Clearly | Longest Substring Without Repeating Characters Leetcode

  Рет қаралды 64,105

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 53
@GregHogg
@GregHogg Жыл бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@dantemix
@dantemix Жыл бұрын
Please never stop this series.
@gabedailey3249
@gabedailey3249 Жыл бұрын
Always have trouble visualizing sliding window keep it up dawg
@mfaani
@mfaani Ай бұрын
This is a great video. It just gives you the main idea needed. And that’s really what we all need for learning about how to code these.
@sevenscapes
@sevenscapes 10 ай бұрын
Great explanation👏👏
@va3802
@va3802 Жыл бұрын
These are helping me with LeetCode while in my freshmen year.🚀
@vm1662
@vm1662 5 ай бұрын
These shorts are amazing. Thank you!
@davea136
@davea136 7 ай бұрын
Excellent explanation. Why am I watching this on a Saturday night?
@masteradvisor594
@masteradvisor594 4 ай бұрын
Please never stop this
@_HariHaranR
@_HariHaranR 9 ай бұрын
Good approach.
@GregHogg
@GregHogg 9 ай бұрын
Glad you think so!
@LukeSorvik
@LukeSorvik 10 ай бұрын
nice explanation
@Malayalam_learner
@Malayalam_learner 3 ай бұрын
Great video
@mohitc4289
@mohitc4289 26 күн бұрын
dude i used to watch you on ig when you abrey had followrrs wow
@smash4929
@smash4929 11 ай бұрын
How simple you want to make it? Greg: YES
@GregHogg
@GregHogg 7 ай бұрын
Can't believe I missed this... Thank you buddy :)
@boring-person-rishabh
@boring-person-rishabh 6 күн бұрын
In java if they are English alphabets use can use an array with a being 0 index b being 1 index and so on
@MrEo89
@MrEo89 Жыл бұрын
Great series, just read up on how to do the visualizing and you will have thousands of followers in no time. Quality > quantity, every time. Edit: also, don’t zoom in as much, you’re constantly clipping the sides of the code snippets off. Set a text width of 60 or zoom out to like 50%. Most phones nowadays have great resolution so if anything we can pinch to zoom at our preference.
@prasad4you57s2
@prasad4you57s2 Жыл бұрын
You made it clear and cool
@kur0sh1
@kur0sh1 Жыл бұрын
if you're using a string you could just use an array of the size if the number of alphabets. Then you could just index the array with something like ['z' - curr_char ]. You still get the access in constant time without the overhead of a hashing function and all you trade for it is a few extra bytes for the array. I really think people should try to do these problems without using built-in data structures and instead should try to implement their own as that helps you so much in getting a better understanding of these algorithms and programming im general.
@d.g.m.04
@d.g.m.04 7 ай бұрын
using maps and sets and what not in these is such an overkill for me its crazy, i'd call it lazy programming lmao
@alwinthomas2288
@alwinthomas2288 5 ай бұрын
Hi should i use cpp over python due to TLE issue??
@methodsystem4251
@methodsystem4251 4 ай бұрын
I have a question if I try to solve the same problem using other techniques Leetcode says Error even though my code is correct. Does Leetcode expect us to solve the problem using only one approach?
@vetiarvind
@vetiarvind Ай бұрын
what's the difference between sliding window vs 2 pointer?
@darcash1738
@darcash1738 6 ай бұрын
As I see it there are two variations to the sliding window, based on what I’ve seen so far. Set subset length(in which you move the right pointer until you get to that length, at which point you can increment both left and right to maintain that length) or undetermined subset length like this, which is based on some condition before you set left = right to start a new subset altogether. Is this correct?
@GregHogg
@GregHogg 6 ай бұрын
Yes you're completely right
@darcash1738
@darcash1738 6 ай бұрын
@@GregHogg awesome, thanks!
@anshusarkar7113
@anshusarkar7113 6 ай бұрын
What is the difference between a set and a hash set ?
@doodledude1976
@doodledude1976 7 ай бұрын
So seeing as how s[r] will always be in the set, can i clear the set, add s[r] to it, and say l = r? I’m trying to get rid of the while loop
@GregHogg
@GregHogg 7 ай бұрын
No, that won't let it slide properly. It needs to expand and contract as needed.
@lil_jeke
@lil_jeke 4 ай бұрын
What’s the TC O(n^2) ?
@giancarlokuosmanen9723
@giancarlokuosmanen9723 2 ай бұрын
O(n)
@beardbarbe2824
@beardbarbe2824 3 ай бұрын
Great video just dont get why you are using a set here. Since you checking if the element is in the set at each iteration… 🤔
@prasad4you57s2
@prasad4you57s2 Жыл бұрын
Please add time and space complexity for all the problems
@GregHogg
@GregHogg Жыл бұрын
O(n) for both :)
@KJ-wf1xz
@KJ-wf1xz 10 ай бұрын
Why it’s On time complexity when you need to search through a set at least once moving to the right.
@KJ-wf1xz
@KJ-wf1xz 10 ай бұрын
If you have a string with no repeating characters, the length of set grow from 1 to n-1. Does it make this problem On^2 time complexity?
@rdubb77
@rdubb77 7 ай бұрын
@@KJ-wf1xz array is only traversed once. O(n)
@HR-pz7ts
@HR-pz7ts Жыл бұрын
So that's where I was wrong. I was using a hashmap instead. And clearing the map when there was a repeat. I never thought of learning this algorithm as I wanted to come up with it naturally but then again I still have hadhset to learn. So I'm still learning.
@overbored1337
@overbored1337 Жыл бұрын
Actually a hashmap is better, or even an array. If you make it store an unique incrementing uint32 is you would only need to erase it on every 4 billion run.
@deleteduser8822
@deleteduser8822 Жыл бұрын
hmm so is this another expression for two pointers ?
@GregHogg
@GregHogg Жыл бұрын
It's definitely an example of using two pointers
@onlyAI..
@onlyAI.. 2 ай бұрын
Isn't it O(n2) ??
@SanSu_Web3
@SanSu_Web3 7 ай бұрын
Why didn't you use a map instead?
@GregHogg
@GregHogg 7 ай бұрын
You could. No need though nothing to map to
@riteshkumar-ve3hs
@riteshkumar-ve3hs 7 ай бұрын
You are only finding unique characters this way, not the longest unique substring. Your code will return max_len = 4 when input is pwwkew but actual answer is 3.
@d.g.m.04
@d.g.m.04 7 ай бұрын
damn you are right. Instead he could have just ran the inner while loop until the character that just occurred on the right is skipped on the left and that guarantees there's only 1 left.
@healthplanetary
@healthplanetary 3 ай бұрын
Wanted in java
@rohitwaghmode2123
@rohitwaghmode2123 5 ай бұрын
giving me TLE on gfg 😭 1038/1071
@ajaymishra1511
@ajaymishra1511 Ай бұрын
now optimize it
@misfries6187
@misfries6187 7 ай бұрын
bro this is n^2 u can do better
@GregHogg
@GregHogg 7 ай бұрын
Actually, it's O(n)! The nested for loop doesn't make it n^2
Can You Reverse a Linked List? | Leetcode 206
0:54
Greg Hogg
Рет қаралды 20 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 466 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 480 М.
LeetCode: The Worst Thing to Happen to Software Engineering
8:03
Coding with Dee
Рет қаралды 154 М.
Prefix Sum in 4 minutes | LeetCode Pattern
4:13
AlgoMasterIO
Рет қаралды 13 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 706 М.