Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

A singly linked list is 95 -> 83 -> 36 -> 42 -> 99 -> 64 -> 72 -> None. The first 5 nodes are reversed in place (the node that was originally the head becomes the tail of that reversed portion, and is then linked to the node that originally followed the 5th node). What is the resulting list?

  1. A. 72 -> 64 -> 99 -> 42 -> 36 -> 83 -> 95 -> None
  2. B. 99 -> 42 -> 36 -> 83 -> 95 -> 72 -> None
  3. C. 99 -> 42 -> 36 -> 83 -> 95 -> 64 -> 72 -> None
  4. D. 95 -> 83 -> 36 -> 42 -> 99 -> 64 -> 72 -> None

Correct answer: C. 99 -> 42 -> 36 -> 83 -> 95 -> 64 -> 72 -> None

Reversing only the first 5 nodes and re-linking the old head to what followed the 5th node gives: 99 -> 42 -> 36 -> 83 -> 95 -> 64 -> 72 -> None

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

Exams that ask this topic