Reverse Words in a String | Top Interview Question 🔥 | LeetCode 75 #6
Placements
0:00 / 0:00
Reverse Words in a String | Top Interview Question 🔥 | LeetCode 75 #6
2 просмотра · 2 недели назад
Placements
2 подписчика
2 просмотра · 2 недели назад
Reverse Words in a String — LeetCode 151 (Medium), explained from ZERO in Hindi.
In this video we reverse the order of words in a string AND clean up the spaces — leading, trailing and multiple spaces — all in-place, with O(1) extra space.
What you will learn:
What a "word" means here (longest run of non-space characters)
All 3 LeetCode examples, animated
The naive idea: split + filter + reverse + join (and why C++ has no split)
The optimal 3-phase trick: reverse the whole string, reverse each word, clean spaces with two pointers i and j
A full animated dry run on "a good example"
C++ code line by line — every syntax explained (std::reverse, isspace, cctype header, while loops, s.resize)
Edge cases: only spaces, single word, already-clean string, empty string
Time O(n), extra space O(1)
Practice here: https://leetcode.com/problems/reverse...
This is video #6 of the LeetCode 75 series in Hindi — 3D animated, beginner-first, every line explained.
#LeetCode #LeetCode75 #DSAinHindi #CodingInterview #Placements #CPlusPlus #TwoPointers #StringManipulation #ReverseWordsInAString #LearnDSA