Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: In the array [9, 3, 7, 3, 9, 1, 7], how many elements are equal to the maximum of the elements to their right (the last element counts as having nothing to its right, so it is excluded from the count)?

  1. A. 2
  2. B. 0
  3. C. 3
  4. D. 1

Correct answer: D. 1

For each index compare the element with the maximum of its suffix to the right. Counting elements that are greater than everything to their right (strict leaders) gives a different number.

More Coding Interview Problems questions

Exams that ask this topic