They saved the best for the last😂. Thank you for explaining so well, it was a really tough problem.
@Sinders9 ай бұрын
changing one of the base cases from i == len(s) to len(s) - i == k helped my runtime dramatically
@khushmeetchugh86699 ай бұрын
it removed my TLE bro thanks
@gmasid9 ай бұрын
Thanks bro, this help TLE too!
@raghavbhatia55489 ай бұрын
@@khushmeetchugh8669 C++ magic
@yang58439 ай бұрын
This removed my TLE for Java, thank you
@karanshah22839 ай бұрын
can you please explain the logic behind this base case change?
@bhavikransubhe72449 ай бұрын
Today's daily leetcode challenge was difficult. Need to look for video 😂
@Drdarker9 ай бұрын
questions like this is almost impossible to solve in a real interview
@ngneerin9 ай бұрын
I see hard and I quit I see medium and I watch I see easy and I solve
@chaunceyzhang65959 ай бұрын
@SmoothCode9 ай бұрын
I relate so hard.
@shashankjoshi82509 ай бұрын
Heyy Bro, your solution and way of explanation was amazing but still I am trying to understand this and how can I come up with this level of intuition to solve the problem. I was able to come up until greedy approach and got 74 passed.
@Caramel-r9w9 ай бұрын
How to do the opposite?
@CheeseStickzZ9 ай бұрын
I mean this is cute and everything, but what the hell is the use of solving these. They have no practical application whatsoever 😂 AKA utter waste of time
@keremt87278 ай бұрын
Shouldn't we also consider the case of deleting s[i] when it is the same as the prev character? Like if we have the string "aaaaaaaaaaaaaaaaaaaaaaaaa..." (25 times a) and the k is 20, then we need to delete so that it is not a25, but a5 instead.
@s200610029 ай бұрын
Well explanation that saved my life!!! I am able to apply what you have taught in the video and solve today's leetcode question. This is encouraging for me !!!
@susmitsingh17759 ай бұрын
man fuck this problem, took me a bloody day to solve
@binitrajshah93549 ай бұрын
didn't understand why it fail in greedy approach here? even when we consider our string as s = ''aaaaaaaaabaaaaaaaaac' and k = 2 s compressed = a9ba9c so deleting minimum window freq element here ''b' & 'c' implie "a18" with lenght 3. can someone explain this?
@SantoshKumar-bu2qr8 ай бұрын
Why does he sounds like Bane (Batman) giving savage dialouges?
@gnaneswarganta99209 ай бұрын
like what if we condensed the string first and later doing the computations
@tony79485 ай бұрын
If I get this on an interview. I'm just going to walk out
@shrn9 ай бұрын
Same solution Runtime 1552 ms Beats 91.00% of users with Python3 Memory 39.88 MB Beats 40.00% of users with Python3 No !dea why leetcode does this sometimes
@urjeans28964 ай бұрын
best explanation for this question. I was so traumatized until seeing this. Thanks for sharing
@stat_life9 ай бұрын
This solution had beaten 100% of users in runtime and memory, LEETCODE is broken
@gary16147 ай бұрын
This is a very difficult question. Thank you for making this video. It makes a little bit more sense now. lol
@caothanhluan18139 ай бұрын
God tier explanation but TypeScript compiler says it TLE when using Map()😂😂😂
@w7028970289702899 ай бұрын
I wrote it in Java version but 122/144 got TLE... Why
@shreehari25899 ай бұрын
How the heck will I come up with this solution on spot in an interview, these problems are real tough
@abhisheksuman45109 ай бұрын
This aproach is giving runtime error due to stack overflow.
@chiragsrivastava42179 ай бұрын
class Solution: def getLengthOfOptimalCompression(self, s: str, k: int) -> int: @cache def dfs(i, k, prev, prev_count): if k
@sauravsingh44979 ай бұрын
Off topic but the discord link in the description Is not working (i wanted to join the server)
@muhammadsodiqtoirov32049 ай бұрын
Thanks bro ! Good explanation Even gpt couldn't solve this problem ...
@RajGupta-cu9hi9 ай бұрын
How to convert it to 2-dp because some solve it in....?
@sidsudhir82319 ай бұрын
clutchhh
@shreyashpandey93519 ай бұрын
How will I be able to develop intuition like that?
@il50839 ай бұрын
Is using func_tools cache to save sometime a bad idea in an interview? (for memoization)
@mindrust2039 ай бұрын
Couldn't we just get the encoded string first and try to shrink it with a recursive function? Or will the addition of computing the encoded string give a TLE? EDIT: Nevermind this won't work, I thought run-length encoding would transform a string like "aabbaa" into "a4b2", but the encoding is actually "a2b2a2". If k = 2 in this case, the minimum length string would be "a4" with length 2. Indeed a hard problem.
@0ManPiano09 ай бұрын
Lol I was so happy in the beginning thought “oh! That’s not HRAD!” Codes up this exact solution in like 10 min then also ran into this test case. Banged my head for the rest 30 min then gave up, lol. But after watching this solution does make me believe the condensed list will still work if we keep track of the previous character, which I did not implement this resulting in the failed case you gave.
@MayankUpadhyaya-y2q9 ай бұрын
Thank you for explaining the solution. you are really brilliant and extraordinary.
@shawn_yg13949 ай бұрын
The example2 is indicating that minheap does not work but I still waste time for that...
@shashankjoshi82509 ай бұрын
Nah. it will work for example 2. I tried it.. greedy passes 74 tc.
@shubhamraj259 ай бұрын
The same solution in Python beat 79% of users for me
@tanishq82119 ай бұрын
I dont understand why he did ... note updated the deleted character? can somebody explain?
@0ManPiano09 ай бұрын
Don’t understand your question
@ujjwalmaheshwari23279 ай бұрын
class Solution { mapdp; int solve(string &s, int k, int i, char prev, int prevCnt){ if(k
@v-free9 ай бұрын
It may be because you are using map, which is ordered and slow. Use unordered_map instead. You need to define a hash function since you are using a vector as key. struct vector_hash { size_t operator()(const vector& v) const { hash hasher; size_t seed = 0; for (int i : v) { seed ^= hasher(i) + 0x9e3779b9 + (seed2); } return seed; } }; unordered_map dp;
@lokeshmehar39494 ай бұрын
@@v-free hey can u tell how i can learn to make custom comparator and custom hashfunction i have tried it from some of the internet tutorials (mostly written ones) please lmk know if u have some resource or tips for me to help me learn those thank u
@pradyumnasingh95559 ай бұрын
thank you for such an easy explanation :)
@chaunceyzhang65959 ай бұрын
Thanks for your persistence do this video series!
@tranquoctoan19969 ай бұрын
Thank you, it saved me
@ish909179 ай бұрын
do we add cache evetime in question of DP or backtracking ? If not when do we add them ?
@suhaanbhandary40099 ай бұрын
We add cache when we know that for a given set of input the output is same and their should also be overlapping sub-problems. In backtracking cache is of no use as mostly the sub problems are independent and doesn't occur more than once eg: Sudoku, but in DP same sub-problems occur eg: Fibonacci(try to draw tree of recursive call to better visualize).
@pritz99 ай бұрын
To memoize the recursive solution, otherwise you are gonna get a TLE.
@w7028970289702899 ай бұрын
What an explanation...
@ronniey42319 ай бұрын
Can’t love your videos more😂
@GuruPrasadShukla9 ай бұрын
great explaination man! keep going bro!
@aryakadam78929 ай бұрын
thank you
@krateskim41699 ай бұрын
Thank you so much
@chien-yucode9929 ай бұрын
So amazing
@BTCSEDarshan9 ай бұрын
Saviour !
@ajaybabua97359 ай бұрын
Can someone please explain me about the increment part 14:04 to 16:00?
@w7028970289702899 ай бұрын
Because when we encounter 1 -> 2 (a -> a2) 9 -> 10(a9 -> a10) 99 -> 100(a99 -> a100) all of these cases will result in answer to be plus by 1 and the rest of the case don't need to do this because the length remain the same like 3 -> 4(a3 ->a4)
@aswinnath85809 ай бұрын
your explanation helped me to understand that part.@@w702897028970289
@anonymousperson44669 ай бұрын
why is it so hard.....goddamn
@0ManPiano09 ай бұрын
This one is hard, isn’t it.
@anonymousperson44669 ай бұрын
@@0ManPiano0 I'm having a hard problem everyday...at least one.....this one's painfully hard for me
@racoon-thespy70629 ай бұрын
bruhh, in the morning doing the problem, guy has already got the solution ready, hats off
@SiddharthReddy169 ай бұрын
No way you actually make difficult problems with such clarity! I visit this channel every day, no matter how easy/hard the daily question is just to see your approach.
@thangavn88758 ай бұрын
phenomenal work, you gained a sub and a follower 💯