GATE Computer ScienceModerateGATE CS (PYQ pattern)

A singly linked list 1 -> 2 -> ... -> 20 undergoes two passes: first every 3rd node (by current position) is deleted, then in the resulting list every 4th node (by current position) is deleted. What is the sum of the remaining nodes?

  1. A. 126
  2. B. 104
  3. C. 147
  4. D. 114

Correct answer: D. 114

After deleting positions 3, 6, ..., 18 the list is [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20]; deleting every 4th of those removes [5, 11, 17]; the remaining sum is 114.

More Programming and Data Structures (GATE) questions

Exams that ask this topic