Decode String - Leetcode 394 - Python

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


0:00 - Read the problem
3:45 - Drawing Explanation
12:07 - Coding Explanation

leetcode 394

#decode #string #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
Рекомендации по теме
Комментарии
Автор

The fact that you appended the string AFTER the pop made the problem so easy. I was shaking my head in horror trying to reverse the string once after appending it.

gazijarin
Автор

Very comprehensive problem to practice stacks! Together with asteroid collision and daily temps, one can argue understanding those 3 problems alone are a solid prep for stack problems on interviews.

TheElementFive
Автор

this was asked in my amazon sde 1 interview somehow i managed t solved it. holy cow!

Iamnoone
Автор

Did this myself and came to see the solution. I am so happy to see my progress. Thank you soooo much!!!

ShivangiSingh-wcgk
Автор

I know you probably hear this a lot but your explanations are so clear and easy to grasp. Thanks a ton for this.

harishsn
Автор

Amazingly explained, was able to implement without even looking at code. Thank you!

shubhamshrivastava
Автор

Great explanation and diagrams!! This is what I got:

The things to decode have this pattern: Coefficient(content)
2 things needed:coefficient, and content

My approach using stack was adding just the {}, and tracking the indexes for substring
, but I like your approach is cleaner by adding everything to stack.
General approach:
for all chars in string
if stack is Empty:
if isDigit: calculate the numerical part/coefficient,
if (, add to stack, save startindex
if is character, add to string builder
if stack is not empty:
add everything
if is ), remove from stack
if stack is empty, recursively call helper(s.substring(startIndex+1, endIndex)

deathbombs
Автор

You explain these problems so well! can you please do a video on the problem " Guess the word" ?

susmi
Автор

One of the best solution availabe on YT. Great work sir. Huge fan of the way you break tough and/or complex problems into simpler versions!!😍😍

arghya_
Автор

Love your videos, the clearest explainations I've come across among all the other ones ... Keep it up!

cherylto
Автор

You make things feel so easy!
Thank you so much 😀

amogchandrashekar
Автор

First coding channel on Youtube that I put the bell icon to receive all updates for !!

AnupBhatt
Автор

According to LeetCode premium, the time complexity of this solution is actually O(maxK^countK * n), where maxK is the maximum value of k, countK is the count of nested k values and n is the maximum length of the encoded string. Example, for s = 20[a10[bc]], maxK is 20, countK is 2 as there are 2 nested k values (20 and 10). Also, there are 2 encoded strings a and bc with the maximum length of the encoded string n as 2.

LeetCodeSimplified
Автор

Best explanation man! TYSM for your efforts.

kashishshukla
Автор

Great clear explanation as always. thanks

chenhaibin
Автор

Thanks, i ended up solving this with recursion on my first attempt. I used this video to learn how to apply stacks to the problem. Thank you.

brandenimmerzeel
Автор

wow usually I feel a bit anxious when not able to come up with a soln, I have been watching ur few vids! explanations r crisp and easy to understand, I even like it's in python while I code in cpp lol

october
Автор

I don't know why I am still using java. I came up with the same solution with a stack but it is at least twice longer thanks to java. This is so easy to read and comprehend.

begenchorazgeldiyev
Автор

Great video! Thanks! This problem showed me stacks are amazing for accruing and backtracking in an organic way!

pif
Автор

Explanation put very simple way, thanks for this!

atulkumar-bbvi