Data Structures & AlgorithmsHardTCS NQT · Accenture

Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are greater than 7, and report the count plus the index of the largest element overall.

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

Correct answer: B. 1

The count of greater elements to the right of index 2 is 1 (only 8), and the maximum 9 sits at index 0. The sum of these two values is 1, which is the answer.

More Coding Interview Problems questions

Exams that ask this topic