Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse Character Array In Place

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Reverse Character Array In Place. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

At Spotify, a text-processing utility stores strings as mutable character arrays. Write a function that reverses the array in place without allocating another array for the result.

Given a list of characters s, modify s so that its characters appear in reverse order.

Formal Specification

  • Input: s — a list of single-character strings
  • Output: Do not return a new list. Modify s directly and return None.

Constraints

  • 1 <= len(s) <= 10^5
  • Each element of s is a single printable character
  • Use O(1) extra space
  • Modify the input list in place

Function Signature

def reverse_string(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output