Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
What is the length of the longest substring of "aebcdiouxyab" in which the number of vowels (a, e, i, o, u) equals the number of non-vowels?
- A. 14
- B. 12
- C. 10
- D. 6
Correct answer: B. 12
Map each vowel to +1 and each other letter to −1; a substring is balanced when its prefix balances are equal, so the longest gap between equal prefix balances gives the answer. Counting only vowels in the window (without the balance) does not measure equality.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many index pairs (i < j) in [4, 9, 1, 7, 12, 5, 8, 3] satisfy a[i] − a[j] = 3 (exactly 3, in this order)?
- Starting from the number 1, each operation either doubles the current number or adds 1. What is the minimum number of operations needed to…
- How many pairs (i, j) with 1 ≤ i ≤ j ≤ 12 have lcm(i, j) ≤ 12?
- Coins of values 1, 4, 9 and 16 are available in unlimited supply. What is the minimum number of coins that makes exactly 27?
- What is the maximum sum of a contiguous subarray of [4, -3, 5, 2, -7, 6, 1, 3] whose length is ODD?
- How many contiguous subarrays of [2, 3, 5, 4, 7, 6, 9] contain EXACTLY two odd numbers?