Alternating Letter Case
Updated
Problem statement
Given a string s, return a new string in which the letters switch between upper case and lower case, one after another. The first letter becomes upper case, the second lower case, the third upper case, and so on.
Only letters take part. Spaces, digits and punctuation are copied unchanged and do not move the pattern forward, so the next letter after them simply takes the next case in turn. A letter gets its case from its place among the letters, whatever case it had in s.
Function
alternateCase(s: String) → StringExamples
Example 1
s = "Hello World 2"return = "HeLlO wOrLd 2"The letters in order are H e l l o W o r l d. They become upper, lower, upper, and so on, so W (the sixth letter) becomes lower case. The spaces and the digit 2 stay as they are.
Example 2
s = "x-ray, ok?"return = "X-rAy, Ok?"The letters x r a y o k become X r A y O k. The hyphen, the comma, the space and the question mark are kept and do not count as letters, so r right after the hyphen is the second letter and becomes lower case.
Example 3
s = "BANK"return = "BaNk"The input case does not matter: the second and fourth letters become lower case even though they were upper case.
Constraints
1 <= s.length <= 10^4sconsists of English letters, digits, spaces and the characters. , ! ? # -
More Bank of America Online Assessment questions
- Return Exact Cash Register ChangeOA · Seen Aug 2026
- Sum Skipping Multiples of 7OA · Seen Nov 2025
- Wildcard Substring MatchOA · Seen Nov 2025
- Maximum String BeautyOA · Seen Sep 2024
- Merge Point of Two Linked ListsOA · Seen Oct 2023
- Remove Duplicates from a ListOA · Seen Oct 2023
- Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
- Count Level-Order Traversals of a TreeOA · Seen Sep 2023
- Count Set BitsOA · Seen Sep 2023
- Count Pairs with Sum KOA · Seen Jun 2023
Similar questions at other companies
- Branch with the Most FilesCapital One · OACapital One interview questions
- Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Filter Isolated Interior Signal BitsSEDEMAC · OA
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Telephone Keypad String EncodingEpic · OAEpic interview questions
- Count Invalid Log GroupsIBM · OAIBM interview questions
- Count Case-Insensitive TripletsTikTok · OATikTok interview questions