Guys it looks like ‘i-1’ isn’t needed, ,y solution passes all test cases when I submit it without that line! Thanks so much,Cush cracking faang for the vid! You probably see me commenting on all your vids now!
@kingfriizy570710 ай бұрын
its a medium because the follow up is solve in constant memory
@barybary425 ай бұрын
which is not that straightforward
@Ammar23217 Жыл бұрын
very good solution
@crackfaang Жыл бұрын
Thanks mate, glad you found it helpful
@arkachaudhuri73396 ай бұрын
Hey, Can someone explain the purpose for the i -= 1 after parsing the string builder? Shouldn't it anyway iterate forth to the next if it encounters a whitespace?
@elias0430116 ай бұрын
He's moving it back WITHIN the if statement because after exiting the if conditional block, he adds to "i" again.. you could get around this by checking ahead in the nested while statement while i + 1 < len(s) and s[i + 1] != " ":
@wentaogao11182 жыл бұрын
Thanks., very nice solution
@crackfaang2 жыл бұрын
Thanks for the kind words! Make sure to subscribe so you don’t miss future videos
@pshi19892 жыл бұрын
thank you 😊
@MohitJain-dt4nb5 ай бұрын
why can't we simply do this-: class Solution: def reverseWords(self, s: str) -> str: words = s.split() return ' '.join(reversed(words))
@GiaBìnhVũ-w4s3 ай бұрын
yoooo that is much better, ty !!
@luucАй бұрын
That's definitely one way to solve it. Though, the idea behind the question is to practice a specific competitive programming pattern (two-pointer). Can you solve it without any memory usage?