> For the complete documentation index, see [llms.txt](https://algorithm.prettylog.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://algorithm.prettylog.com/algorithm-problems/algoexpert/medium/single-cycle-check.md).

# Single Cycle Check

![](/files/dHRAFLLjUTWtzAP2sFy2)

* n, 1

```jsx
function hasSingleCycle(arr) {

  const visited = new Set();

  let currentIdx = 0;
  while (true) {
    if(visited.has(currentIdx)) {
      break;  
    }
    visited.add(currentIdx);
    currentIdx += arr[currentIdx];
    currentIdx %= arr.length;
    currentIdx += arr.length;
    currentIdx %= arr.length;
  }

  return visited.size === arr.length && currentIdx === 0;
}

// Do not edit the line below.
exports.hasSingleCycle = hasSingleCycle;
```
