Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Reverse String

XPChallenge Points: 10
levelLevel: Easy

You are given a string represented as a list of characters s.
Your task is to reverse the string in-place, meaning you must modify the input array directly without using extra memory beyond O(1) space.

You must complete the reversal by swapping characters rather than creating a new list.

Example 1:

Input: s = ["p", "y", "t", "h", "o", "n"]

Output: ["n", "o", "h", "t", "y", "p"]

Example 2:

Input: s = ["O", "p", "e", "n", "A", "I"]

Output: ["I", "A", "n", "e", "p", "O"]

Example 3:

Input: s = ["c", "o", "d", "i", "n", "g"]

Output: ["g", "n", "i", "d", "o", "c"]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result