Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A singly linked list holds 36 -> 38 -> 51 -> 57 -> 28 -> None (in that order, 5 nodes). Using the standard two-pointer technique (advance one pointer 1 nodes ahead, then move both together until the lead pointer reaches None), which value is the 1st node from the end?
- A. 36
- B. 28
- C. 57
- D. 68
Correct answer: B. 28
The list has 5 nodes, so the 1-th from the end is at 0-based index 4, which holds 28.
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
- Evaluate the postfix expression: 4 3 7 + 1 -
- A circular queue is implemented in an array of size 9 with front = 1 and rear = 8 (rear indexes the last stored element, the queue is…
- Quicksort with Lomuto partitioning (last element as pivot) sorts [12, 42, 92, 73, 37, 39, 75, 75, 32]. How many swaps happen in total…
- 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…
- Using a monotonic (increasing) stack to find, for each element of [20, 17, 18, 14, 44, 28], the nearest element to its left that is…
- A monotonic decreasing stack of indices is used to compute the next-greater-element array for [48, 12, 29, 6, 30, 28] (push index i after…