Reverse a String
Updated
Problem statement
You are given a string s. Return a new string that holds the characters of s in reverse order: the last character comes first and the first character comes last.
Every character counts, including spaces, digits and punctuation.
Try to build the answer yourself instead of calling a built-in reverse function.
Function
reverseString(s: String) → StringExamples
Example 1
s = "capital"return = "latipac"Read capital from the last letter to the first: l, a, t, i, p, a, c.
Example 2
s = "Pay $25, now!"return = "!won ,52$ yaP"Spaces, digits and punctuation are reversed just like letters. The last character ! comes first and the first character P comes last.
Example 3
s = " a"return = "a "The leading space is a character too, so it ends up at the end.
Constraints
1 <= s.length <= 5000scontains only printable ASCII characters (character codes32to126), including spaces.
More Capital One Online Assessment questions
- Rank Football TeamsOA · Seen Oct 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
- Arithmetic Triplets After QueriesOA · Seen Oct 2026
- Branch with the Most FilesOA · Seen Oct 2026
- Count One-Swap Number PairsOA · Seen Oct 2026
- Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
- Earliest Meeting Time for All EmployeesOA · Seen Oct 2026
- Earn the Most 🐝OA · Seen Oct 2026
- Sort Adjacent PairsOA · Seen Oct 2026
- Bouncing Diagonal WeightsOA · Seen Oct 2026
Similar questions at other companies
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
- Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
- Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Reverse Vowels of a StringGoogle · ONSITE INTERVIEWGoogle interview questions
- Valid Palindrome After NormalizationKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Count Binary SubstringsDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Run-Length String CompressionSalesforce · OASalesforce interview questions
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
Capital One interview experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)