LeetCode Decode String Solution Explained - Java

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

This question pissed me off to the depths of hell

TrenBlack
Автор

No one.
literally no one.
Nick White : "Uhh, Its pretty straight forward."

anuragv
Автор

It is always suggested to NOT use Java's 'Stack' implementation during coding interviews and instead 'Deque' could be used. This is because java's Stack implementation extends Vector which is a synchronised data structure and hence must not be preferred for data which do not require synchronisation. Also, Deque is an interface implemented by LinkedList which holds it as an advantage over Stack, which is a class.

premkumareaswaran
Автор

My coding practice routine usually involves being unable to solve medium level questions on leetcode and then coming to your channel for guidance. Your explanation, although a bit fast for my sorry brain, was very helpful.

Do u create these explanation videos once you've practiced the questions yourselves or is it just fresh off the list??

That brain freeze was so relatable. I go completely blank on many questions. Any tips??

chepaiytrath
Автор

Your solution and coding of it was nice, so thank you!
Suggestion:
-I think it would have been helpful if you ran through the solution with an example because the thought/intuition behind the solution could have been explained further for better understanding.

Royceroni
Автор

Why would I think of using two stacks in the first place! :/

palak
Автор

Great video. Just 1 suggestion, Could you dry run it and explain just any 1 example so beginers can understand it better.

fawadraghib
Автор

You are a genious. I would see that a companies would not hire you because you can discover many problems that they choose not to look at. I am hoping one day you make something brilliant out of your mind. The way you explain something is so effortless. I am jealous and amaze to see your talent.

phafid
Автор

Hey, that's a good explanation, however instead of initializing the StringBuilder, you can just declare it before the iterative while loop and reset it every-time you encounter a new closing bracket and then start a fresh append from the pop. Something like this
StringBuilder segmentBuilder = new StringBuilder();
int segmentRepeatCount =0;

else if (encodedString.charAt(i) == ']') {


segmentRepeatCount = counts.pop();
for (int k = 0; k < segmentRepeatCount; k++) {

}
result = segmentBuilder.toString();
i++;
}....}
This will optimize the solution further.

swaroopchakraborty
Автор

It would be nice if you explained the solution more seriously instead of emphasizing how blanked out you were. You're supposed to teach people who are seeing this for the first time, not those who are reviewing it again and already write the code by heart (like you did).

arianazin
Автор

Hey Nick, thanks for the explanation. I came across this question today in an interview. I did not come up with 2 stacks approach. It's very hard to come up with this approach if you haven't already solved on leetcode.

MrChinmaykulkarni
Автор

Hell is a place where you're told to solve everything recursively and the call never stack exceeds.

ousmand
Автор

Dont you get null pointer at line 21 when lets say string is [abc]2[a] ?

ramatiwari
Автор

instead of using res variable, it is better to use a StringBuilder as string concatenation is a costly operation

rakshith
Автор

Very well explained. Thank you for the detailed explanation.

ashforwin
Автор

The logic is kinda very hard to think. How could you come up with this solution??

morampudiakhil
Автор

Hey what does the StringBuilder temp= new sB(result.pop()) do ?

daniyaliqbal
Автор

If there's a substring before a number, like "ab2[cd]", when does "ab" ever get added to res?

kairu
Автор

it's always good if you could come up with tracing the algo and parallelly code.. so that it is easy to understand.. anyways good effort

rakshith
Автор

You have result stack and just push once and don’t do anything with it? This code will break in certain use cases.

memosen