Skip to content
Decoder

Reverse String

Easy

Problem

You are given a string as a list of characters s. Reverse it in place: change the list itself and return nothing. Use only O(1) extra memory.

Example 1

Input
s = ["h", "e", "l", "l", "o"]
Output
s becomes ["o", "l", "l", "e", "h"]

Example 2

Input
s = ["H", "a", "n", "n", "a", "h"]
Output
s becomes ["h", "a", "n", "n", "a", "H"]

Constraints

  • 1 <= s.length <= 10^5
  • Every s[i] is a printable ASCII character.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.