Data Structures & AlgorithmsModerate

From the linked list 5 2 13 3 8 7 9 4, delete every node that has a strictly greater value somewhere AFTER it in the list. Which list remains, in order?

  1. A. 5 13
  2. B. 13 9 4
  3. C. 2 3 4
  4. D. 5 2 13 3 8 7 9 4

Correct answer: B. 13 9 4

A node survives only if every later value is ≤ it, so the survivors are the suffix maxima read from the right. Testing the earlier side removes the opposite nodes, and using ≥ also removes equal values that should stay.

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

Exams that ask this topic