Tesco
Online AssessmentVowel-Starting Words in Alphabetically Sorted List
Write a program that takes a list of words as input and sorts the list of words in alphabetically ascending order. Identify words in the sorted list that start with a vowel (a, e, i, o, u) regardless of their case.
Display each of these words along with their 1-based positions in the sorted list, separated by a single space, each on a separate line.
If no word in the list starts with a vowel, print 0 as the output.
- ▸The first line of input contains a list of words with each separated by a single space.
- ▸Print each vowel-starting word and its 1-based position in the sorted list separated by a single space, each on a separate line. If no word starts with a vowel, print 0.
- 1 <= Number of words <= 1000
- 1 <= Length of each word <= 100
- Words consist of uppercase and lowercase English letters.
only god can judge me now
only 6
Given list: ["only", "god", "can", "judge", "me", "now"].
Alphabetically sorted list:
1: can
2: god
3: judge
4: me
5: now
6: only
The word "only" starts with the vowel 'o' and is at position 6 (1-based index). Hence the output is 'only 6'.
apple banana elephant orange
apple 1 elephant 3 orange 4
Sorted list: ["apple", "banana", "elephant", "orange"]. Words starting with vowels are at positions 1, 3, and 4.
rhythm sky crypt
0
None of the words start with a vowel, so 0 is printed.
1. Read all space-separated words from the input line. 2. Sort the list of words in standard ascending alphabetical order. 3. Iterate through the sorted list (using 1-based index i from 1 to N): - Check if the first character of word[i-1] is a vowel (a, e, i, o, u, case-insensitive). - If it is a vowel, print `<word> <i>` and mark a boolean flag `found = true`. 4. If `found` remains false after checking all words, print `0`. 5. Runs in O(N log N * L) time and O(N * L) space.