Reverse words in a string 🙅‍♂️ In-place algorithm explained. Leetcode 186, 151, 557

preview_player
Показать описание
Reverse Words in a String with space removal is an awesome problem to practice .. Every interview aspirant must practice it. Watch it multiple times to master these tricks and techniques that I am teaching here. This problem involves the famous two pointers' technique and the mirror reverse method.

All this solution have Time O(N) and Space O(1) complexities

0:00 Introduction
1:30 Reverse words in a sentence (LC - 557)
7:16 Intro to the second problem
8:21 Reverse sentence by words (LC - 186)
12:54 Reverse sentence by words skip spaces (LC - 151)
23:25 Final Take-Aways

Leetcode problem links :

#reversewords #leetcode #interviewdose

"never say never" Reverse Words in a String problem will master you in pointers manipulation "Step by Step" :)

My intention is not just to show you the solutions here but it's a **step by step** approach that someone should take while solving a problem in the real interview when he doesn't know a solution. Trust me it will be worth your session. feel free to share your feedback.
Рекомендации по теме
Комментарии
Автор

Best explanation of this problem on YouTube! Salute to you sir this is excellent!

chrisyeung
Автор

Excellent explanation, Keep up the good work!

mayankjain
Автор

really good approach, explanation with multiple examples that's great for understanding. applaud🚀🚀

princepatoliya
Автор

Thank you, Sir! Great Video! Well explained!

alhaithamaljabri
Автор

Very concise and clear solution..!! Kudos..!

prateekjhabak
Автор

I saw you wrote for loop in different way. For(;i <j; i++, j--). This is something new. Is this the different way to write for loop? Can you please explain?

natureculturefoodlover
Автор

Very nice concept and very well elaborated. Thankyou so much sir for clearing my concept. Would like to see more lectures like this., 👍

amandeepak
Автор

Many peoples mentioned to use stack in the last leetcode problem you explained, is it enough to know that?

tusharnain
Автор

can you please explain this code to me, it is very complicated

mehdinouira
Автор

Sir, I have tried to follow your tutorial but I am unable to get the expected output. Can you please provide some feedback? Here is my code:

class Solution {
//mirror image
void reverse(char[]str, int i, int j){
for(;i<j;i++, j--){
char temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}

public String reverseWords(String s) {

char[]str=s.toCharArray();

int i=0;//backward pointer
int j=0;//forward pointer

while(j<=str.length){
if(j==str.length || str[j]== ' '){
reverse(str, i, j-1);
i=j+1;
}
j++;
}
return new String(str);
}
}

alisonlee