LeetCode 394. Decode String [Solution + Code Explained ]

preview_player
Показать описание
One of the most frequently asked coding interview questions on Strings in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.

LeetCode 394. Decode String

Question : Given an encoded string, return its decoded string.

The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.

You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.

Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won't be input like 3a or 2[4].

Examples:

s = "3[a]2[bc]", return "aaabcbc".
s = "3[a2[c]]", return "accaccacc".
s = "2[abc]3[cd]ef", return "abcabccdcdcdef".

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

Great videos for difficult interview questions. Great work Jayati. Thanks

lifekool
Автор

Thankyou for this deep explanation, I was only searching for this type of understanding. <3

nandiniverma
Автор

You made this question too easy. Thank you very much. Channel link posted in Leetcode discuss section.

K_EC_AushoRoup
Автор

Really very nice and clear explanation.thanks a lot!

KajalKumari-gmqg
Автор

It isn't as trivial as it looks. Great explanation!

vaibhavteli
Автор

Very good and clear explanation. Please make more videos.

gourabmitra
Автор

great Explanation!! can u please explain how to do this question by recursion

Bakasta
Автор

one stackcan suffice, only thing is we need to pop and push continuously as ] is encountered, assuming each [ bracket is preceded by a number

chandanchandak
Автор

Can someone compare iterative solution vs recursive solution, in terms of time complexity and suggest which one is better approach?

vaidehidharkar
Автор

Thank you for your concise explanation. I am a fan of your videos.
I see that that you have a slide for when to apply a particular approach.
Can you share those slides?

ravipandhi
Автор

Can u share the approaches sheet you use in every question?

hardikagarwal
Автор

ctrl c + ctrl v nick white's video great work

vaibhavkumar
Автор

we use ss stack to store strings, but we never actually popped anything from the ss stack tho?

sophiezhang
Автор

One suggestion is to explain the case that the char is number, and then explain the case that the char is integer, then the case that char is open/close bracket. I see some 'you will understand as we complete the code' which isn't really the best way to explain.

sjy
Автор

dont you get null pointer at line 22 for lets say string is [abc]2[bc]

ramatiwari
Автор

Hi do you or does anyone else know if I can find the answer to this question in C?

animegamer
Автор

Thanks for the awesome explanation...I had a question
How is the time complexity O(n) ?
You are using a outer while loop and an inner for loop for appending, so shouldn't it be O(n^2)?

luciferg
Автор

thhoda hindi me hi bol deti didi...ye itna jyada technical word kahogi to kaha se smjh aaega ....ham log khud yaha seekhne aae hain.

ShauryaVlogX