Loading...
Detect Cycle in Sequence
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- junior
Problem
Our dependency resolver needs to detect infinite loops in task chains. Given a list of integers where each value points to the next index to visit (-1 means end), determine whether following the chain from index 0 revisits an index. Return True if a cycle exists.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.