Reverse String
Difficulty: Easy · Topic: Stacks & queues
Given a string s, return it reversed. Try it with a two-pointer swap, a loop that prepends, or Python slicing.
Examples
reverse_string("hello")
→ "olleh"reverse_string("Algolume")
→ "emuloglA"reverse_string("a")
→ "a"Target complexity: time O(n), space O(n)
Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.
Learn the idea first: the lesson for this problem.