Data Structures & AlgorithmsHardProduct company OA

A singly linked list holds 10 → 21 → 32 → 43 → 54 → 65. It is rearranged so that all nodes at ODD positions (1st, 3rd, …) come first, followed by the nodes at even positions, each group keeping its relative order. What is the result?

  1. A. 21 → 43 → 65 → 10 → 32 → 54
  2. B. 10 → 32 → 54 → 65 → 43 → 21
  3. C. 10 → 32 → 54 → 21 → 43 → 65
  4. D. 10 → 21 → 32 → 43 → 54 → 65

Correct answer: C. 10 → 32 → 54 → 21 → 43 → 65

Positions, not values, decide: positions 1, 3, 5 hold 10, 32, 54 and positions 2, 4, 6 hold 21, 43, 65. Splitting by ODD VALUES (21, 43, 65 first) is the trap; the result is built by relinking two chains in one pass with O(1) extra space.

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

Exams that ask this topic