reverseString

Easy · String Manipulations · 2 test cases

Given a string, return a new string with the reversed order of characters.

Examples

reverseString('hello') → 'olleh'
reverseString('world') → 'dlrow'

Starter code

function reverseString(str) {

}

Complexity of the optimal solution

Time O(n), space O(n). The solution involves splitting the string into an array (O(n)), reversing the array in place (O(n)), and joining it back into a string (O(n)). The overall time is O(n), and space is O(n) for the intermediate array.

Solve reverseString in the browser