Data Structures & AlgorithmsVery hard
A linked list has nodes numbered 0 to 9 in order, and node 9's next pointer returns to node 3. Two pointers start at node 0: slow moves one node per step and fast moves two. At which node number do they first meet?
- A. 3
- B. 9
- C. 7
- D. 8
Correct answer: C. 7
Once both pointers are in the loop (nodes 3 to 9, a cycle of length 7), fast gains one node per step on slow, so they meet after a bounded number of steps at a node inside the cycle. The loop entry node 3 is the start of the cycle, not the meeting point here.
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
- In the sorted array [1, 1, 2, 2, 3, 4, 4, 5], how many different VALUE pairs {x, y} with x < y satisfy x + y = 6? (Repeated copies of a…
- Among all permutations of 1, 2, 3, 4 in which no two ADJACENT entries sum to 5, which one is lexicographically smallest? Give it as a…
- What is the smallest positive integer that is NOT the sum of any CONTIGUOUS (adjacent) block of [1, 2, 4, 8]?
- How many ways can [1, 2, 3, 4, 5, 7] be cut into one or more contiguous, non-empty segments so that EVERY segment has an even sum?
- How many contiguous subarrays of [1, 2, 1, 3, 2, 1, 4, 2, 3] contain each of the values 1, 2, ..., L exactly once, where L is the subarray…
- How many contiguous subarrays of [1, 2, 3, 3, 2, 1, 4, 4] have even length and equal sums in their left half and right half?