Reverse String Problem

Problem Write a function that takes a string as input and returns the string reversed. Examples Example 1: Given s = "hello", return "olleh". Given s = “kodeknight” , return “thginkedok“. Solution Method 0 - Iterative, Not in Place In Java, string is immutable. So, cannot do in place!. public String reverseString(String s) { int n = s.length; char[] reversed = s.toCharArray(); return reverse(reversed); } ...

Reverse Linked List Problem

Problem Reverse a linked list. Follow up 1 - Do it in-place and in one-pass. Follow up 2 - Can you do it with only 2 pointers. Examples For example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL ...

Reverse a string in C using as little additional memory as possible

Problem Question: Reverse a string in C using as little additional memory as possible. Solution Answer: The first solution needs the size of a char and size of two integers, all of which will be allocated from the stack. This solution is the most commonly accepted “good” solution. Here is the code. Method 1 - Using 2 pointer technique We have already seen Reverse String Problem#Method 1 - Iterative in-place using Two Pointers ...

August 11, 2022 · 2 min · TagsList of tags for the post  bits ·  reverse

Reverse Linked List 2 - between m and n

Problem Reverse a linked list from position m to n. Do it in-place and in one-pass. OR Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list. Examples Example 1: --- title: Input --- graph LR A1[1] --> B2[2]:::reversed --> C3[3]:::reversed --> D4[4]:::reversed --> E5[5] classDef reversed fill:#ffcc00,stroke:#000,stroke-width:2px; ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy