Data Structures & AlgorithmsHardTCS NQT · Stacks

For each element of [4, 5, 2, 25, 7, 8], take the first strictly greater element to its right (or -1 if there is none). What is the sum of these values?

  1. A. 64
  2. B. 61
  3. C. 53
  4. D. 62

Correct answer: B. 61

Next greater values are 5, 25, 25, -1, 8, -1, which sum to 61.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic