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,
2,
1,
3,
1,
2,
2
]
Execution steps
Cancel groups of three
Computed output
[
1,
2
]
JavaScript reference implementation
const solve = (a,s)=>{
let m=new Map;
for(let x of a){
if(m.has(x))m.set(x,m.get(x)+1);
else if(m.size<2)m.set(x,1);
else for(let [k,v] of m){
if(v===1)m.delete(k);
else m.set(k,v-1)
}
s("Cancel groups of three",{
Array:a,Candidates:[...m].map(p=>p.join(":"))
})
}
return [...m.keys()].filter(x=>a.filter(y=>y===x).length>a.length/3).sort((x,y)=>x-y)
};