DSA interview question
You're writing two helpers for a quiz app. The first receives the scores of everyone who took today's quiz and must report the sum and the highest score. Scores can be negative, because wrong answers cost points. The second receives the player's display name and must report how many vowels and how many consonants it contains, ignoring spaces, digits and punctuation, for a "name power" badge. Both are small, but they force you to use the two most basic containers correctly: indexing an array safely, starting a maximum from a real value, and treating a string as an array of characters.
Example: scores [3, 9, 2] → sum 14, max 9; name "Hello World" → 3 vowels, 7 consonants.
pair<long long, int> sumAndMax(const vector<int>& scores); // {sum, max}; scores is non-empty
pair<int, int> countVowelsConsonants(const string& name); // {vowels, consonants}
| Input | Output | Explanation |
|---|---|---|
scores [3, 9, 2] | sum 14, max 9 | Basic case |
scores [-5, -1, -7] | sum -13, max -1 | Starting max at 0 would wrongly return 0 |
scores [4] | sum 4, max 4 | Single element |
name "Hello World" | vowels 3, consonants 7 | The space is ignored |
name "AEIOU xyz" | vowels 5, consonants 3 | Uppercase vowels count too |
name "R2-D2" | vowels 0, consonants 2 | Digits and - are not letters |
name "" | vowels 0, consonants 0 | Empty string |
(Confirm: the scores array has at least one element; only English letters count; 'y' is treated as a consonant.)
vector? Are strings mutable?"long long.)a[n] in an array of size n?"vector?"s = s + c in a loop slow?"On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in