Reverse a String
Updated
Problem statement
Given a string s, return a new string containing the same characters in reverse order.
Preserve character case, spaces, digits, and punctuation. An empty input returns an empty string.
Function
reverseString(s: String) → StringExamples
Example 1
s = "FastPrep"return = "perPtsaF"Reading FastPrep from right to left produces perPtsaF.
Example 2
s = "a b!"return = "!b a"The punctuation and space remain characters and move to their reversed positions.
Example 3
s = ""return = ""The reverse of the empty string is the empty string.
Constraints
0 <= s.length <= 200000scontains only printable ASCII characters.
Similar questions at other companies
- Run-Length Encoding and DecodingAirbnb · PHONE SCREENAirbnb interview questions
- Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Reverse a StringAmazon · PHONE SCREEN
- Reverse a String ManuallyNewgen Software · PHONE SCREEN
- Reverse a String with Two PointersSnowflake · PHONE SCREENSnowflake interview questions
- Palindrome with One DeletionWhatNot · PHONE SCREENWhatNot interview questions
- Valid Word AbbreviationMeta · PHONE SCREENMeta interview questions
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Valid Palindrome IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions