Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A singly linked list is 47 -> 24 -> 78 -> 79 -> 98 -> 29 -> 13 -> None. The standard iterative in-place reversal (prev = None; while cur: nxt = cur.next; cur.next = prev; prev = cur; cur = nxt) is run on it. What does the list look like afterwards?
- A. 47 -> 29 -> 98 -> 79 -> 78 -> 24 -> 13 -> None
- B. 24 -> 78 -> 79 -> 98 -> 29 -> 13 -> 47 -> None
- C. 13 -> 29 -> 98 -> 79 -> 78 -> 24 -> 47 -> None
- D. 47 -> 24 -> 78 -> 79 -> 98 -> 29 -> 13 -> None
Correct answer: C. 13 -> 29 -> 98 -> 79 -> 78 -> 24 -> 47 -> None
Each node's next pointer is flipped to point to the previous node, reversing the whole list: 13 -> 29 -> 98 -> 79 -> 78 -> 24 -> 47 -> None
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Using the sliding window technique, what is the maximum sum of any 8 consecutive elements in [24, 30, 4, 27, 25, 2, 13, 22, 26, 1]?
- A singly linked list has nodes at positions 0..6 holding 58 -> 20 -> 49 -> 17 -> 78 -> 37 -> 22, but the last node's next pointer points…
- Heap sort (build a max-heap, then repeatedly swap the root with the last unsorted element and sift down) is run on [1, 27, 40, 40, 63, 2…
- A monotonic decreasing stack of indices is used to compute the next-greater-element array for [41, 35, 17, 34, 4, 37, 29, 44] (push index…
- What is the space complexity of this recursive factorial function, as a function of n (ignoring the final integer result size)? c int…
- Evaluate the postfix expression: 6 3 + 7 + 9 +