Loading
Loading
A malformed configuration can make a processing chain point back into itself, so following it never terminates.
The input describes the node values plus a loopIndex: the position the last node links back to, or -1 for no loop. Return true if the chain loops.
Note that the input arrives as a plain value list and a loop index, so your function receives the values and the index rather than a pre-built cyclic list.
values = [3, 2, 0, -4], loopIndex = 1slow=3, fast=3start togetherslow=2, fast=0one step vs twoslow=0, fast=2fast has wrapped aroundslow=-4, fast=-4they meet — a loop existstrueSign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
The tail links back to index 1.
Example 2
Example 3