Magicsheet logo

Count the Number of Vowel Strings in Range

Easy
77.5%
Updated 6/1/2025

Asked by 1 Company

Count the Number of Vowel Strings in Range

What is this problem about?

The Count the Number of Vowel Strings in Range coding problem asks you to count how many strings in a given array (within a specific range of indices [left,right][left, right]) are "vowel strings." A vowel string is defined as a string that both starts and ends with a vowel ('a', 'e', 'i', 'o', 'u').

Why is this asked in interviews?

PayPal uses this "Easy" question to test basic array slicing and character validation. It evaluations if a candidate can correctly iterate over a sub-segment of an array and perform multiple character checks on strings. It’s a foundational problem used to ensure a candidate is comfortable with basic syntax and logic.

Algorithmic pattern used

This problem uses a simple Linear Scan with Character Validation.

  1. Define a set of vowels: {'a', 'e', 'i', 'o', 'u'}.
  2. Initialize a count = 0.
  3. Loop through the array from index left to right inclusive.
  4. For each string at index i:
    • Check if the first character s[0] is a vowel.
    • Check if the last character s[s.length() - 1] is a vowel.
    • If both are true, increment count.
  5. Return the count.

Example explanation

words = ["apple", "hello", "ice", "orange"], left = 0, right = 2

  1. Index 0: "apple". Starts with 'a', ends with 'e'. (Vowel string!) -> Count = 1.
  2. Index 1: "hello". Starts with 'h' (No).
  3. Index 2: "ice". Starts with 'i', ends with 'e'. (Vowel string!) -> Count = 2. Total = 2.

Common mistakes candidates make

  • Out of range: Forgetting to use right as inclusive in the loop.
  • Empty strings: Not checking if a string is empty before accessing s[0] or the last character.
  • Vowel set: Missing a vowel (usually 'u' or 'o') or including 'y'.

Interview preparation tip

For "Easy" problems, focus on edge cases and clean code. Mentioning that you used a Set for vowels because it provides O(1)O(1) lookup shows that you think about efficiency even in simple tasks.

Similar Questions