Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

Array [5, 2, 8, 1, 9, 3] is processed in one left-to-right pass: each node is deleted if its value is strictly greater than the value of the node immediately after it in the original list (the last node is always kept). How many nodes remain?

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

Correct answer: C. 3

Compare each node with its original successor, not with the node that survived before it. Deleting based on the updated neighbour changes the count.

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

Exams that ask this topic