๐ŸŒ
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....
Discussions

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
๐ŸŒ r/leetcode
12
4
April 23, 2024
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
๐ŸŒ r/leetcode
29
6
May 24, 2022
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
๐ŸŒ r/leetcode
2
0
March 1, 2022
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
๐ŸŒ r/learnpython
12
36
May 9, 2023
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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 ยท
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Medium
medium.com โ€บ codex โ€บ 557-reverse-words-in-a-string-iii-take-it-easy-ddc4898328f
557. Reverse Words in a String III : Take it easy | by Coding Aspirants | CodeX | Medium
October 3, 2023 - 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 edoCteeL tsetnoc" Example 2: Input: ...
๐ŸŒ
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