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,
2
]
Execution steps
Swap pivot with successor
Reverse suffix
Computed output
[
2,
1,
3
]
JavaScript reference implementation
const solve = (a,s)=>{
let i=a.length-2;
while(i>=0&&a[i]>=a[i+1])i--;
if(i>=0){
let j=a.length-1;
while(a[j]<=a[i])j--;
[a[i],a[j]]=[a[j],a[i]];
s("Swap pivot with successor",{
Array:a
},[i,j])
}
let l=i+1,r=a.length-1;
while(l<r){
[a[l],a[r]]=[a[r],a[l]];
s("Reverse suffix",{
Array:a
},[l,r]);
l++;
r--
}
return a
};