Data Structures & AlgorithmsHardGATE CS · TCS NQT

For the array [1, 3, 2, 4], take the next strictly greater element of each position (-1 if none) and sum these values, ignoring the -1 entries. What is the sum?

  1. A. 12
  2. B. 11
  3. C. 9
  4. D. 15

Correct answer: B. 11

The next-greater values are 3, 4, 4 and -1; the -1 entry is excluded, so the sum is 11. Including the -1 entry gives 10.

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

Exams that ask this topic