Python data engineering interview problem. Difficulty: intermediate. Pattern: Linked Lists. About 14 minutes. Part of the Pro drill bank.
Detect a cycle using values and a cycle start index. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement has_cycle(values: list, pos: int) -> bool. Build a singly linked list from values. If pos >= 0, connect the last node to the node at index pos. Use Floyd's algorithm.
Input: has_cycle([3, 2, 0, -4], 1) Output: True Tail links to index 1.
Topics: lakebench, python, floyd, cycle.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Detect a cycle using values and a cycle start index.
Implement `has_cycle(values: list, pos: int) -> bool`. Build a singly linked list from `values`. If `pos >= 0`, connect the last node to the node at index `pos`. Use Floyd's algorithm. Example: `[3, 2, 0, -4], 1` → `True`. Keep the harness.