Reverse Vowels of a String
Real-world version: Marquee Vowel SocketsThe statement here is our own: the same inputs, outputs and technique.
A theatre spells the evening listing on its marquee out of character tiles clamped along one rail. A tile sits in a loose socket when its character is a, e, i, o or u, written either as a capital or in lower case. Every other tile on the rail is riveted down and cannot be moved, whatever character it shows.
The stagehand lifts all of the loose tiles off the rail, holds them, and drops them back into exactly the same sockets, but working from the far end of the rail towards the near end. The upshot is that the loose tiles occupy the same positions as before with their order along the rail turned around, while every riveted tile is untouched. Tiles are never re-cut, so a capital tile stays a capital wherever it lands.
You are given the current marquee text as the string board, made of printable ASCII characters. Return the text the marquee shows once the stagehand steps back.
Examples
Example 1
- Input
- board = "TOP hat"
- Output
- "TaP hOt"
Two tiles are loose, the capital in position 1 and the lower-case one in position 5. They trade sockets, and each keeps the case it was cut with.
Example 2
- Input
- board = "Grand Opening"
- Output
- "Grind epOnang"
The four loose tiles sit in positions 2, 6, 8 and 10; reading them back to front gives the tiles that land in those same four positions. The space and every riveted tile stay put.
Example 3
- Input
- board = "myrtle"
- Output
- "myrtle"
Only one tile here is loose, so lifting it and dropping it back changes nothing. A tile showing the letter y is riveted like any other consonant tile.
Constraints
- 1 <= board.length <= 3 * 10^5
- board consists of printable ASCII characters.
- A tile is loose only for the ten characters a, e, i, o, u, A, E, I, O, U.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def marquee_vowel_sockets(board: str) -> str:public String marqueeVowelSockets(String board)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's