Комментарии:
Thank you
Ответить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.
Ответить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;
while(.....){
else if (encodedString.charAt(i) == ']') {
segmentBuilder.setLength(0);
segmentBuilder.append(words.pop());
segmentRepeatCount = counts.pop();
for (int k = 0; k < segmentRepeatCount; k++) {
segmentBuilder.append(result);
}
result = segmentBuilder.toString();
i++;
}....}
This will optimize the solution further.
Thank you, well understood.
ОтветитьPls elaborate the explainnation taking some test case then write the code all are not pro in leetcode
ОтветитьCurrently it's 9ms in Leetcode..... : ()
ОтветитьHey what does the StringBuilder temp= new sB(result.pop()) do ?
ОтветитьYou have result stack and just push once and don’t do anything with it? This code will break in certain use cases.
ОтветитьSorry but u didn't explain it well
Ответитьyou are awesome man
ОтветитьCan someone compare iterative solution vs recursive solution, in terms of time complexity and suggest which one is better approach?
ОтветитьDont you get null pointer at line 21 when lets say string is [abc]2[a] ?
ОтветитьU could have explained it with an example before starting implementation
ОтветитьGreat video. Just 1 suggestion, Could you dry run it and explain just any 1 example so beginers can understand it better.
ОтветитьIR :(
ОтветитьIf there's a substring before a number, like "ab2[cd]", when does "ab" ever get added to res?
Ответить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.
I'd rather suggest a recursion solution that is much more intuitive and weirdly ran in 0ms.
string getString(string s,int n,int &i)
{
string res;
int ct=0;
string val;
while(i<n)
{
if(int(s[i])>=97 && s[i]<=122)
res.push_back(s[i]);
else if(s[i]>='0' && s[i]<='9')
{
val.push_back(s[i]);
}
else if(s[i]=='[')
{
int x=stoi(val);
val.clear();
i++;
string temp=getString(s,n,i);
for(int j=0;j<x;j++)
res.append(temp);
}
else if(s[i]==']')
return res;
i++;
}
return res;
}
string decodeString(string s)
{
int n=s.size(),i=0;
return getString(s,n,i);
}
No one.
literally no one.
Nick White : "Uhh, Its pretty straight forward."
not optimal solution, you gotta use recursion
ОтветитьHe seems high
ОтветитьYou forgot adding the # of this leetcode question
Ответитьwhats the time complexity for this solution?
ОтветитьThank you for this video, Nick! Really appreciate what you do!
Ответитьinstead of using res variable, it is better to use a StringBuilder as string concatenation is a costly operation
ОтветитьThis is the worst video i've seen you made. Please set a higher expectation for yourself.
Ответить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.
ОтветитьWhat was the intuition behind using a stack in this question?
Ответитьnice and neat solution. Thanks for the upload!
Ответить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??
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).
ОтветитьHell is a place where you're told to solve everything recursively and the call never stack exceeds.
Ответить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.
ОтветитьRuntime & Space complexity?
Ответитьwhy minus zero on line 12?
ОтветитьWhy would I think of using two stacks in the first place! :/
Ответитьexcellent
ОтветитьThe logic is kinda very hard to think. How could you come up with this solution??
Ответить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
ОтветитьThis question pissed me off to the depths of hell
ОтветитьNice logic Nick
ОтветитьSuper
Ответить