LeetCode
leetcode.com โบ problems โบ reverse-string-ii
Reverse String II - LeetCode
Reverse String II - Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them.
AlgoMap
algomap.io โบ problems โบ reverse-words-in-a-string
Reverse Words in a String
Split the string into words: Use ... automatically collapses multiple spaces between words. Reverse the list of words: Use a built-in reverse function or reverse loop to change the order of the words....
Videos
04:16
Reverse Words in a String - LeetCode 151 - Python #leetcode75 - ...
06:16
Reverse Words In A String - 151. LeetCode - Java - YouTube
Reverse Words In A String III (LeetCode 557) | Full solution | ...
09:24
151. Reverse Words in a String - LeetCode - JavaScript - YouTube
10:18
Reverse Words in a String III - Leetcode 557 - Python - YouTube
07:02
151. Reverse Words in a String | JavaScript | LeetCode | Daily ...
Reverse words in a string using multithreading?
UPDATE: Since the question was clarified. I'll have to change my answer slightly. Input: "The cat is a dog" Output: "dog a is cat The" One trick to solve this problem is to reverse the entire string once and then reverse the words. So something like this: "The cat is a dog" => "god a si tac ehT" => "dog a is cat The" So you could parallelize the first step. That would require you to choose smaller chunks of ranges within the larger range of 0 to n/2 And then you could parallelize the second step, but only after the first step is completely done. And the second step would look like what I was describing earlier: A helper function called reverseWords(str, start int, end int) This would allow you to process the str chunk by chunk independently on different threads. You would just need to ensure that the cut off points only land on spaces (so as not to cut a word in half). Then, it just becomes a two pointer problem, or you could use a stack if you prefer. More on reddit.com
Today's daily challenge "Reverse words in a string" - Python Solution
return " ".join(filter(lambda x:len(x)!=0,s.split(" ")[::-1])) More on reddit.com
issue in mu code in --> 151. Reverse Words in a String
For the last word 'blue' it adds all letters by using 'if' condition but when 'i' becomes 'n-1' it still executes 'if' condition and 'else' is not executed,hence the last word doesn't get pushed into the stack . You will have to add another check at last that if word.length!=0 then push word. More on reddit.com
reversing a string LeetCode question
Does the leetcode question require you to reverse the string in place or to return a reversed version of the string? If it is the first one, that is why the second option doesn't work for you. Lists are passed by reference in Python as opposed to being passed by value. s[:] = s[::-1] #this modifies the memory space that s is pointing to. s = s[::-1] #this sets s to a new list in a new location in memory. More on reddit.com
edSlash
edslash.com โบ home โบ leetcode challenge #151. reverse words in a string
LeetCode Challenge #151. Reverse Words in a String - edSlash
December 3, 2023 - If โhelperโ is not empty , it means the last word has been collected , and it will be added to the โansโ . โข The code reverses the the order of characters in โhelperโ and directs it to โansโ , and ensures that there is no extra space at the end. 4. Finally, the string with reversed words is stored in โansโ, and it is returned as a result.
LeetCode
leetcode.ca โบ all โบ 186.html
Leetcode 186. Reverse Words in a String II
Given an input string , reverse the string word by word.
Codepath
guides.codepath.org โบ compsci โบ Reverse-Words-in-a-String-II
Reverse Words in a String II | CodePath Cliffnotes
Go through the input List while start < n: # 3. Determine where the word end - find each word in the input List while end < n and l[end] != ' ': end += 1 # reverse the word self.reverse(l, start, end - 1) # move to the next word start = end + 1 end += 1
WalkCCC
walkccc.me โบ LeetCode โบ problems โบ 557
557. Reverse Words in a String III - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
Medium
kanghui-liu.medium.com โบ leetcode-186-reverse-words-in-a-string-ii-m-17bc726be94c
Leetcode 186: Reverse Words in a String II (M) | by BigRabbitData | Medium
January 21, 2025 - """ s.reverse() start_index = 0 for index, letter in enumerate(s): if letter == ' ': s[start_index: index] = reversed(s[start_index: index]) start_index = index + 1 # Remember to reverse the last word if there is leftover word s[start_index:] = reversed(s[start_index:]) Runtime O(n), Space O(1) Leetcode Medium ยท
GitHub
github.com โบ doocs โบ leetcode โบ blob โบ main โบ solution โบ 0100-0199 โบ 0151.Reverse Words in a String โบ README_EN.md
doocs/leetcode - 0151.Reverse Words in a String
<strong>Explanation:</strong> You need to reduce multiple spaces between two words to a single space in the reversed string.
Author ย doocs
MyTechRoad
zxi.mytechroad.com โบ home โบ ่ฑ่ฑ้
ฑ leetcode 151. reverse words in a string
่ฑ่ฑ้
ฑ LeetCode 151. Reverse Words in a String - Huahua's Tech Road
November 28, 2021 - Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces. ... Input: s = " hello world " Output: "world hello" Explanation: Your reversed string should not ...
AlgoMonster
algo.monster โบ liteproblems โบ 186
186. Reverse Words in a String II - In-Depth Explanation
In-depth solution and explanation for LeetCode 186. Reverse Words in a String II in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
LeetCode
leetcode.com โบ problems โบ reverse-vowels-of-a-string
Reverse Vowels of a String - LeetCode
Reverse Vowels of a String - Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.
LeetCode
leetcode.com โบ problems โบ reverse-words-in-a-string
Reverse Words in a String - LeetCode
Can you solve this real interview question? Reverse Words in a String - Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters.
LeetCode
leetcode.com โบ problems โบ reverse-linked-list
Reverse Linked List - LeetCode
Reverse Linked List - Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: [https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg] Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: ...
LeetCode
leetcode.com โบ problems โบ reverse-words-in-a-string-iii
Reverse Words in a String III - LeetCode
Reverse Words in a String III - Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat ...
AlgoMonster
algo.monster โบ liteproblems โบ 151
151. Reverse Words in a String - In-Depth Explanation
In-depth solution and explanation for LeetCode 151. Reverse Words in a String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
LeetCode
leetcode.com โบ problems โบ reverse-words-in-a-string-ii
Reverse Words in a String II - LeetCode
Can you solve this real interview question? Reverse Words in a String II - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
GeeksforGeeks
geeksforgeeks.org โบ dsa โบ reverse-words-in-a-given-string
Reverse words in a string - GeeksforGeeks
Reverse the entire string, then iterate through it to extract words separated by dots. Reverse each word individually and update the original string until the end is reached.
Published ย October 29, 2025