Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A singly linked list holds 50 -> 31 -> 76 -> 53 -> 96 -> None (in that order, 5 nodes). Using the standard two-pointer technique (advance one pointer 5 nodes ahead, then move both together until the lead pointer reaches None), which value is the 5th node from the end?
- A. 50
- B. 31
- C. 61
- D. 60
Correct answer: A. 50
The list has 5 nodes, so the 5-th from the end is at 0-based index 0, which holds 50.
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
- Quicksort with Lomuto partitioning (last element as pivot) sorts [52, 89, 77, 41, 89, 97, 29, 94]. How many swaps happen in total, across…
- A singly linked list has nodes at positions 0..5 holding 38 -> 23 -> 89 -> 67 -> 63 -> 79, but the last node's next pointer points back to…
- Two nested loops iterate: the outer runs n times, and for each outer iteration the inner loop runs from 1 up to the current outer index i…
- What is the time complexity of binary searching for a value in a sorted array of n elements, then linearly scanning the next k elements…
- What does this code compute, and what is its time complexity for an array of n elements? c int best = a[0]; for (int i = 1; i < n; i++) if…
- Quicksort uses the Lomuto partition with the last element as pivot on [99, 24, 44, 86, 76, 60, 84, 3]. After one partition call, at which…