FastPrepReverse a String
Problems/Reverse a String

Reverse a String

Capital One logoCapital One● EasyFULLTIMEOAONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2025 Capital One report says the first of four coding assessment questions was to reverse a string, and the candidate found it very easy. A 2016 Capital One onsite report also had this task. The interviewer stopped it early to ask how Java's StringBuilder and StringBuffer differ.

The reports do not give the input format or limits. Here, the string has 1 to 5000 printable ASCII characters and you return a new reversed string. Avoiding a built-in reverse is a suggestion and tests do not check it. The StringBuilder question is covered in the editorial.

Our version is about 90% the same as the reported questions.

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) → String

Examples

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 <= 5000
  • s contains only printable ASCII characters (character codes 32 to 126), 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)
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public String reverseString(String s) {
        // Write your code here.
    }
}
Checking account…