Data Structures & AlgorithmsModerateTCS NQT · cycle detection
Problem: What is the purpose of the 'Floyd cycle detection' algorithm?
- A. Sorting an array
- B. Finding a cycle in a functional graph or sequence using two pointers
- C. Computing shortest paths in a DAG
- D. Counting primes
Correct answer: B. Finding a cycle in a functional graph or sequence using two pointers
The tortoise and hare pointers meet inside the cycle, and a second pass finds the entry point.
More Coding Interview Problems questions
- Problem: What is the Euler characteristic relation used for planar graphs?
- Problem: How many monotone (right and up) lattice paths from (0,0) to (5,7) pass through the point (2,3)? Run the code. python from math…
- Problem: A grid has 4 rows and 4 columns. Cell (r, c) holds value (r·c) mod 3. Starting at (0,0), a path moves right or down to (3,3)…
- Problem: The string "mississippi" has its letters counted. What is the number of distinct letters that appear an odd number of times?
- Problem: Start with 7, multiply it by 3, then repeatedly replace the number by the sum of its decimal digits until a single digit remains…
- Problem: The array [4, 1, 3, 2, 5] is processed by counting sort on the values 1 to 5, writing the values into an output array in sorted…