codekofi
← All problems

Problem 66

Medium

1 · Worked examples

0 / 4

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 4 outputs correctly.

The accepted solution

1int solution(const vector<int>& nums) {
2
3 int slow = 0;
4 int fast = 0;
5
6 do {
7 slow = nums[slow];
8 fast = nums[nums[fast]];
9 } while (slow != fast);
10
11 slow = 0;
12
13 while (slow != fast) {
14 slow = nums[slow];
15 fast = nums[fast];
16 }
17
18 return slow;
19}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.