Take K of Each Character From Left and Right - Leetcode - Python

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


0:00 - Read the problem
0:30 - Drawing Explanation
11:05 - Coding Explanation

leetcode 2516

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

Glad I managed to solve this problem before watching your video using sliding window pattern! This approach is very similar to "LC 1423: Maximum Points You Can Obtain from Cards" problem. Practicing every day is the key - you'll start noticing patterns over time. Thanks again for such an elegant solution!

galactus
Автор

My man, I made the same mistake of implementing DFS with backtracking. Did it in 5 mins and passed 118/142 test cases. What came next was sadness ...

vuongbinhan
Автор

you mentioned a couple of videos ago that you would stop leetcode daily problem videos for a while to get your work done, but seeing this problem I'm really glad you didn't. Coz it would have been tough for me to wrap my head around this seeing the editorial, thanks for that mate!

satyadheeraj
Автор

Another way to think about this problem is a totally normal two pointer on a circular array. Instead of stopping when j gets to n, you just keep going. You instead stop when i gets to n, and make sure the length of the window is less or equal to n. so j never gets ahead of i by wrapping around the array.

junkman
Автор

This one was hard to wrap my head around even after looking at the editorial, thanks for the simple explanation!

trueinviso
Автор

broo it was like ek dum se wakt badal diya jazbaat badal diye case when he inversed the problem itself

arihantsinghrana
Автор

I was trying to solve it optimally with a circular array technique, 10 mins later realised yea this ain't gonna work. Learned something new today. Thanks Neetcode!

mohakkapoor
Автор

so happy to see youre still doing these daily problems with us even though youre busy thank you 🙏🙏

jody
Автор

the daily problems this month follow a certain alg/data structure so these past days have a been sliding window focus

FatCowFat
Автор

superb sir, loved the way you explain the intuition behind the problem.

BardawalBihari
Автор

You should look at the problem constraints.
A rule of thumb is that computers can run 10**6 operations during testing.
If you plugged in the constraint to your solution's complexity, and it's over 10**6, you will get TLE.

ducpham
Автор

wow. it's so clever to slide window to exclude solution

JamesBond-mqpd
Автор

How about a two pointer approach. Keep a map for counts of a, b, c. Move the pointer for which m[char] <k and add minute. If both have been filled just increase and decrease each pointer.

pratiksinha
Автор

bro so you explained a different way in theory, like you said increment left pointer and right pointer to right + 1 in case of failure but in code you incremented left by 1 in while loop. I am confused. Check timestamp 9:59

humeilmakhija
Автор

5:41 - Invert, always invert! Jacobi, 1830s

ivandrofly
Автор

Could *_res_* be initially assigned to *_len(s)_* instead of *_float("inf")_* ?

EdWestfieldJr
Автор

I have a question, if the question is asking for minimum number of mins does that not mean our window needs to be as large as possible while maintaining the frequency of a-c >= k? So, I don't understand how taking the min window is giving out the correct answer. I know this solution works but can't understand updating the result part.

salmansattar
Автор

nice code. Mine is messy but yours is clean

hoyinli
Автор

I am new to this, and although I understood this. This part of the code count[ord(c) - ord("a")] += 1 seems genius to me. like how do u come up with subtracting ASCII to return 0 1 2. Damn.

PsychoDude
Автор

damn. ☝ this. i immediately thought it is a backtrack with memo so dp... but cheated and checked the topic(my guess wasn't correct). so not to go this hard route...

barbosleetcode
welcome to shbcf.ru