REVERSE WORDS IN A STRING | LEETCODE 151 | PYTHON SOLUTION

preview_player
Показать описание
In this video we are solving a popular Microsoft interview question: Reverse Words in a String.

This is a medium level question on Leetcode but really it's quite simple and just involves some string parsing. Realistically the only tricky part is dealing with the fact that there can be multiple whitespaces in the string but otherwise it's smooth sailing.

Make sure to subscribe to the channel if you enjoyed this video!
Рекомендации по теме
Комментарии
Автор

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!

dnm
Автор

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?

arkachaudhuri
Автор

its a medium because the follow up is solve in constant memory

kingfriizy
Автор

why can't we simply do this-:
class Solution:
def reverseWords(self, s: str) -> str:
words = s.split()
return ' '.join(reversed(words))

MohitJain-dtnb