String processing
Filed under TCS
Free read 3 of 3Determine if the operations should be performed independently on the original input string.
The question
Implement a function that takes a string and returns a dictionary containing the string with vowels removed, the string with vowels uppercased, and a string of characters at even indices.
Constraints
- Input string length up to 1000
- Vowels are defined as 'a', 'e', 'i', 'o', 'u'
Examples
- Input
- 'apple'
- Output
- {'removed': 'ppl', 'uppercased': 'ApplE', 'even': 'ape'}
- Why
- Vowels are processed and even indices (0, 2, 4) are extracted.
Approach
Determine if the operations should be performed independently on the original input string.
Iterate through the string to identify vowels and apply the uppercase or removal logic.
Use Python's slicing syntax [::2] to efficiently extract characters at even indices.
Handle empty strings or strings containing no vowels to ensure the function is robust.
Solution
O(N) time, O(N) space
class Solution:
def process_string(self, s: str) -> dict:
vowels = 'aeiouAEIOU'
# Remove vowels
no_v = ''.join([c for c in s if c not in vowels])
# Uppercase vowels
up_v = ''.join([c.upper() if c in vowels else c for c in s])
# Even indices
even = s[::2]
return {'removed': no_v, 'uppercased': up_v, 'even': even}
Tips
- What they are testing: Check strings with only vowels, only consonants, or empty strings to ensure robustness.
- Common mistake: Modifying the string in-place during iteration, which is inefficient and impossible for immutable strings.
Related TCS questions
Collected from public candidate posts and coding forums. Updated Nov 2026.