Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: In the array [3, 5, 2, 8, 6, 1], the number of elements that are greater than every element after them (right leaders) is counted. The last element always qualifies. How many right leaders are there?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Scan from the right, keeping the running maximum; each new maximum is a right leader. Counting left-to-right maxima instead gives a different number.
More Coding Interview Problems questions
- Problem: A monotone sequence is built: start with 1, and append the next number as (previous number) + (number of digits of previous…
- Problem: The numbers 1 to 20 are split into odd numbers and even numbers. What is the absolute difference between the sum of the odd…
- Problem: A string of length 5 uses the letters x, y, z. How many such strings contain each of the three letters at least once?
- Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the…
- Problem: Starting with the number 100, subtract the square of the smallest prime factor of the current number each step (the number is…
- Problem: The string "xyzxyzxyz" is split into 3 equal blocks of length 3. The blocks are compared: how many pairs of blocks (i < j) are…