Reverse a String
Updated
Problem statement
Given a string s, return the string made of the same characters in the opposite order. The last character of s becomes the first character of the result, and the first character becomes the last.
Spaces, digits and punctuation count as characters too, and each letter keeps its case.
Function
reverseString(s: String) → StringExamples
Example 1
s = "spring 2021"return = "1202 gnirps"The last character, 1, now comes first, and the first character, s, now comes last. The space still sits between g and 2, which have swapped sides.
Example 2
s = "Ok, go!"return = "!og ,kO"The string has 7 characters. The comma and the exclamation mark move like any other character. The space is the middle character, so it stays where it is. O stays upper case.
Example 3
s = "A-1"return = "1-A"The hyphen stays in the middle, and A and 1 trade places.
Constraints
1 <= s.length <= 10^4sconsists of English letters, digits, spaces and the characters.,!?-
More Bank of America Onsite Interview questions
- Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
- Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
- N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
- Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
- Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
- Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
- Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
- Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
- Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
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
- 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
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
- Reverse A StringNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Validate a Word AbbreviationSalesforce · ONSITE INTERVIEWSalesforce interview questions