Alternating Case
Go through the letters of s and count only the letters (skip every other character). Make the 1st, 3rd, 5th... letters uppercase and the 2nd, 4th, 6th... letters lowercase. Characters that are not letters stay as they are. Return the new string.
Example 1
s "hello world"
returns "HeLlO wOrLd"
Letters alternate across the space: HeLlO wOrLd.
Constraints
0 <= len(s) <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Capitalize the TitleBeginner
- Center in a FieldBeginner
- Chunks From the LeftBeginner
- Consecutive CharactersBeginner
- Count Capitalized WordsBeginner
- Count Differing PositionsBeginner
- Count Prefixes of a Given StringBeginner
- Defanging an IP AddressBeginner