Reverse a string

Beginner Problems Basic Strings Easy
  • The reverse string problem and its underlying concept of in-place algorithm with limited space complexity have a lot of practical applications
  • This concept is crucial in fields like data processing where memory space is a prime concern
  • For instance, when building content editing software such as those used in blogs or publishing tools, features like undo-redo management or palindrome checking often leverage the idea of reversing a string or sequence in-place
  • Even in popular databases, the optimization of data manipulation and retrieval operations uses these techniques
  • Sometimes, a clever application of such reversal logic can lead to efficient software solutions

Given a string, the task is to reverse it. The string is represented by an array of characters s. Perform the reversal in place with O(1) extra memory.


Note: no need to return anything, modify the given list.

Examples:

Input : s = ["h", "e" ,"l" ,"l" ,"o"]

Output : ["o", "l", "l", "e", "h"]

Explanation : The given string is s = "hello" and after reversing it becomes s = "olleh".

Input : s = ["b", "y" ,"e" ]

Output : ["e", "y", "b"]

Explanation : The given string is s = "bye" and after reversing it becomes s = "eyb".

Input : s = ["h", "a" ,"n" ,"n" ,"a", "h"]

Constraints

  • 1 <= s.length <= 105
  • s consist of only lowercase and uppercase English characters.

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree