Get Equal Substrings Within Budget - Leetcode 1208 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
5:45 - Coding Explanation

leetcode 1208

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

I was stuck at how to make take care of difference count, after seeing your difference count array, I immediately figured out that it was sliding window problem, first I solve this with using O(n) space then optimize it to O(N) time and O(1) space, thanks Navdeep 🙂

varunpalsingh
Автор

you actually dont need a while loop. you can just put an if statement because once you find the max window there is no point in shrinking it just keep shifting till the end

chrischika
Автор

you know you watched too much neetcode if you came up with the exact same solution with the exact same variable names 😂

michael._.
Автор

when i saw substring, maximum i know we can solve it by sliding window

AnordinaryMan
Автор

Rather than shrinking the window, once you are at a max size, can't you just shift the window by subtracting the value at the left pointer, and stepping to the next iteration of the for loop? Why waste time considering strings that a shorter than your current max result?

Edit - just tested this, and it works and beats 99+% of Python solutions.

sophiophile
Автор

A sliding window is already on the back of my mind while the explanation is going on.

asagiai
Автор

well i first started with backtracking[misinterpreted the f'king question] then did the sliding window thing

tommyshelby
Автор

This problem is today's challenge may 28

alphaoumardev
join shbcf.ru