MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / cyclicSort

Function cyclicSort

javascript/0041-first-missing-positive.js:14–27  ·  view source on GitHub ↗
(nums, index = 0)

Source from the content-addressed store, hash-verified

12};
13
14const cyclicSort = (nums, index = 0) => {
15 while (index < nums.length) {
16 const num = nums[index];
17 const indexKey = num - 1;
18 const indexNum = nums[indexKey];
19
20 if (canSwap(nums, num, indexNum)) {
21 swap(nums, index, indexKey);
22 continue;
23 }
24
25 index += 1;
26 }
27};
28
29const search = (nums, index = 0) => {
30 while (index < nums.length) {

Callers 1

firstMissingPositiveFunction · 0.70

Calls 2

canSwapFunction · 0.85
swapFunction · 0.70

Tested by

no test coverage detected