Data Structures & AlgorithmsHardAmazon OA · Linked List

A singly linked list 1 -> 2 -> ... -> 7 is reversed in groups of k = 2; a final group with fewer than k nodes is left as it is. What is the resulting order?

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

Correct answer: A. 2 1 4 3 6 5 7

Complete pairs (1,2), (3,4), (5,6) are swapped within themselves; the lone node 7 stays.

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

Exams that ask this topic