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
{
"a": [
1,
2,
3,
6,
2,
3,
4,
7,
8
],
"k": 3
}
Execution steps
Consume consecutive group
Computed output
true
JavaScript reference implementation
const solve = ({
a,k
},s)=>{
let m=new Map;
for(let x of a)m.set(x,(m.get(x)||0)+1);
for(let x of [...m.keys()].sort((a,b)=>a-b))while(m.get(x)){
let g=[];
for(let j=0;
j<k;
j++){
if(!m.get(x+j))return false;
m.set(x+j,m.get(x+j)-1);
g.push(x+j)
}
s("Consume consecutive group",{
Group:g,Counts:[...m].map(p=>p.join(":"))
})
}
return true
};