HomeInterview QuestionsGiven a list of strings strs and a list of indices…

Given a list of strings strs and a list of indices orderInd, rearrange strs according to orderInd and produce a list of tuples where each tuple contains the string and its vowel count.

🟢 Easy Coding Junior level
1Times asked
Aug 2026Last seen
Aug 2026First seen

💡 Model Answer

Iterate over the indices in orderInd, fetch the corresponding string from strs, count its vowels, and append a tuple to the result list. Vowel counting can be done by checking each character against a set of vowels. Complexity is O(n * m) where n is the number of strings and m is the average string length. Example in Python:

python
def rearrange_with_vowel_count(strs, orderInd):
    vowels = set('aeiouAEIOU')
    result = []
    for idx in orderInd:
        s = strs[idx]
        count = sum(1 for ch in s if ch in vowels)
        result.append((s, count))
    return result

# Example usage:
strs = ["hello", "waltham", "I", "am", "here"]
orderInd = [3, 4, 1, 0, 2]
print(rearrange_with_vowel_count(strs, orderInd))
# Output: [('am', 1), ('here', 2), ('waltham', 2), ('hello', 2), ('I', 1)]

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500