Sliding Window Algorithm - Longest Substring Without Repeating Characters (LeetCode)

preview_player
Показать описание
Check out my interview prep platform for learning the patterns!

Here is a step by step explanation of the algorithm problem "Longest Substring Without Repeating Characters" on the LeetCode platform. This problem is asked at many tech companies including Google, Facebook, Amazon, Uber, Adobe, and many more. In this tutorial video, I go over the sliding window technique.

A sliding window algorithm will form a window, or section, around parts of the data. Incrementally, this window will move over the data and perform some sort of computation. To solve it, we must initialize an i and j pointer mapping to our 0 index in our string. We also must initialize a set data structure to keep track of characters we have seen in our window and a max variable. We move the i pointer forward adding each character to our set. If the character is already in our set, we start moving our j pointer forward and removing at each step. After removals, we will compute the length of our window which is i - j + 1 and assign that value to our max variable.

The time and space complexity of our sliding window solution is O(N) where N is the number of characters we have in our input string.

⭐️ Timestamps ⭐️
00:00 - Introduction
00:25 - Problem Overview
00:54 - Brute Force Approach
01:30 - Sliding Window Overview
02:02 - Full Example Walk-through
06:39 - Code Walk-through
09:21 - Time and Space Complexity

----------------------------------------------------
Better Days by Lakey Inspired
Рекомендации по теме
Комментарии
Автор

Finally understood this algorithm after one full day . Great explanation:)

rahulmarkonda
Автор

literally THE BEST explanation on YouTube for this LC question. Thank you, Michael

domdom_hello
Автор

Fantastic animation. It makes the explanation clearer and better.

smarchz
Автор

the double while loop increase the time complexity to O(N2), the concept behind the sliding window approach is to slow down the finding of substring. If you have a string of 1000 charcater it increase its time complexity to 1000 * 1000 =

matteopreda
Автор

Was confused a lot with this problem.. You made it very simple. Thank you so much! Keep up the good work.

srinadhp
Автор

Thank you so much. I have seen almost 10 videos on understanding this question but this was the best explanation for this question.

sarahsharma
Автор

Thanku so much bro! I watched multiple videos to try and understand the algorithm of this problem and gotta say your video was the most helpful atm

didactics
Автор

First time I ever heard about sliding windows. I was completely clueless. This content is subscription worthy, thanks!

SoyDelSouth
Автор

Top notch algorithm solution explanation! Could not have asked for any better. Be blessed!

lumsism
Автор

Best sliding window explanation in the internet, please make more algorithm explanation videos.

felipemelendez
Автор

Wow! This explanation really resonated with me. Not to sound overly dramatic, but for me, this was a great programming performance.
Excellent "whiteboard" explanation, along with the followup explanation while coding to reinforce what was discussed on the whiteboard.
All accomplished in about 10 minutes.

waynegreen
Автор

you're saving lives out here man. keep up the good work!!

Metachief_X
Автор

Clean and concise explanation, very helpful. Thank you :) Never understood the concept of the sliding window better! Kudos! (y)

swathiupadhyaya
Автор

The video editing made this extremely enjoyable and easy to follow. Thumbs up from me

Ronnyhlim
Автор

the new video style with animation makes the problem be easier to understand. Thank you

phuongvy
Автор

Got this question on an interview. I knew sliding window was the approach, but I couldn't get it in time. I never thought to implement it with two pointers as you did here. Thankfully I've moved onto the next stage of the hiring process, but if I ever see this problem again, now I'll know an easy solution! Thanks.

jonathansaraco
Автор

Thankyou ! you got a new subscriber,
I was just exploring the explanation from last 6 hours
and finally, your video helped me a lot...
tysm !!!!

karanvirsagar
Автор

The most underrated technical channel, you are doing a awesome awesome awesome job men...

lapujain
Автор

The explanation with the animation was incredibly well. Keep it up bro 👍.

prasenjitsingharoy
Автор

The clearest explanation I have come across so far. Thanks!

alibaba