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?

  1. A. 4
  2. B. 3
  3. C. 2
  4. 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

Exams that ask this topic