FastPrepReverse String In Place
Problems/Reverse String In Place

Reverse String In Place

The Walt Disney Company logoThe Walt Disney Company● EasyFULLTIMEOAPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: "Reverse a string in O(1) space."

The report does not give the input form or character bounds. Here, the string is a mutable array of up to 2000 printable ASCII characters, including an empty array. Return that array after reversing it.

The judged task matches the report at about 85%.

Reverse the character array chars in place and return that same array.

Use O(1) auxiliary space. Do not build another array or string whose size grows with the input. The returned array is the mutated input; output serialization does not count as auxiliary space.

Function

reverseString(chars: char[]) → char[]

Examples

Example 1

chars = ["h","e","l","l","o"]return = ["o","l","l","e","h"]

Swap h with o, then e with the second l. The middle l stays in place, giving olleh.

Example 2

chars = ["a","b"]return = ["b","a"]

One swap exchanges the two characters, giving ba.

Constraints

  • 0 <= chars.length <= 2000
  • Each element is one printable ASCII character, with code from 32 through 126.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public char[] reverseString(char[] chars) {
        // Write your code here
    }
}
Checking account…