Easy · Linked Lists
Linked List Cycle
Given the head of a singly linked list, return true if following next pointers ever reaches the same node twice (the list has a cycle) and false if the walk ends at null. In the samples, loopAt is the 0-based index the tail links back to, or −1 when the tail ends in null.
Examples
Example 1
{
"values": [3, 2, 0, 4],
"loopAt": 1
}Output: true
Example 2
{
"values": [1, 2, 3, 4, 5],
"loopAt": -1
}Output: false
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.