Back to questionsDSA Visualizers: 388 Coding Questions Find Duplicate Number visualizer Learn Find Duplicate Number with a step-by-step Arrays visualizer, JavaScript source code and a worked example. Practice optimization and matrix.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 5 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input [
1,
3,
4,
2,
2
] Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = (a,s)=>{
2 let l=a[0 ],r=a[0 ];
3 do{
4 l=a[l];
5 r=a[a[r]];
6 s("Floyd cycle meeting",{
7 Array:a,Pointers:[l,r]
8 },[l,r])
9 }
10 while (l!==r);
11 l=a[0 ];
12 while (l!==r){
13 l=a[l];
14 r=a[r];
15 s("Find entrance",{
16 Array:a,Pointers:[l,r]
17 },[l,r])
18 }
19 return l
20 };
Execution canvas Active ChangedSTEP 1 Floyd cycle meeting Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Arrays · Optimization and matrix
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input [
1,
3,
4,
2,
2
] Execution steps Floyd cycle meeting Find entrance Computed output 2 JavaScript reference implementation const solve = (a,s)=>{
let l=a[0],r=a[0];
do{
l=a[l];
r=a[a[r]];
s("Floyd cycle meeting",{
Array:a,Pointers:[l,r]
},[l,r])
}
while(l!==r);
l=a[0];
while(l!==r){
l=a[l];
r=a[r];
s("Find entrance",{
Array:a,Pointers:[l,r]
},[l,r])
}
return l
};Continue learning Practice related DSA questions in the same topic.