PPractick

DSA interview question

Arrays and Strings Basics: Score Summary and Letter Count

Easy · Algorithms · Topics: language basics

The problem

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.

Function signature

pair<long long, int> sumAndMax(const vector<int>& scores);  // {sum, max}; scores is non-empty
pair<int, int> countVowelsConsonants(const string& name);   // {vowels, consonants}

Test cases

InputOutputExplanation
scores [3, 9, 2]sum 14, max 9Basic case
scores [-5, -1, -7]sum -13, max -1Starting max at 0 would wrongly return 0
scores [4]sum 4, max 4Single element
name "Hello World"vowels 3, consonants 7The space is ignored
name "AEIOU xyz"vowels 5, consonants 3Uppercase vowels count too
name "R2-D2"vowels 0, consonants 2Digits and - are not letters
name ""vowels 0, consonants 0Empty string

(Confirm: the scores array has at least one element; only English letters count; 'y' is treated as a consonant.)

How interviewers phrase it

Clarifying questions to ask

  1. Can the array be empty? Can it contain negative numbers?
  2. How large can the values and the array get? (Decides whether the sum needs long long.)
  3. For the string: should uppercase letters count? Should 'y' be a vowel? What about spaces, digits and punctuation?
  4. Is the string plain ASCII, or can it contain Unicode characters?

Follow-ups to expect

  1. "Why is array access O(1)?"
  2. "What happens if you access a[n] in an array of size n?"
  3. "C-style array vs vector?"
  4. "Are strings mutable?"
  5. "How do you convert a character to uppercase or check if it's a letter?"
  6. "Why is s = s + c in a loop slow?"

Practise questions like this with a real engineer

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 interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in