Data Structures & AlgorithmsHardProduct-company MCQ pattern
Floyd's cycle detection runs on a linked list 1 → 2 → ... → 8 whose last node's next pointer points back to node 4 (0-based position 3). Slow moves one step, fast moves two steps per iteration until they meet. At what value do they first meet, and what value starts the cycle?
- A. meet 4, cycle start 4
- B. meet 6, cycle start 5
- C. meet 6, cycle start 4
- D. meet 7, cycle start 4
Correct answer: C. meet 6, cycle start 4
Simulating slow/fast pointer positions until they coincide gives the meeting node with value 6. Resetting one pointer to the head and advancing both one step at a time, they meet again exactly at the cycle's start, value 4 — this works because the head-to-start distance equals the meeting-point-to-start distance modulo the cycle length.
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
- Array [36, 53, 71, 81, 12, 18, 20, 26] is a sorted array rotated at pivot 4. Using the standard O(log n) rotated-array binary search…
- Binary search for first/last occurrence runs on the sorted array [2, 7, 9, 11, 16, 16, 17, 18] for target 16. What (first index, last…
- A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(6)?
- A min-stack (push/pop O(1), getMin O(1) via an auxiliary stack tracking the running minimum) runs this sequence in order: push(-4), pop()…
- Binary search for first/last occurrence runs on the sorted array [1, 5, 6, 7, 10, 13, 18, 19, 19, 20, 21] for target 19. What (first…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "CBCAACACBABCB" are anagrams of "CAB"?