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": "1432219",
"k": 3
}
Execution steps
Remove larger preceding digits
Computed output
"1219"
JavaScript reference implementation
const solve = ({
a,k
},s)=>{
let st=[];
for(let x of a){
while(k&&st.length&&st.at(-1)>x){
st.pop();
k--
}
st.push(x);
s("Remove larger preceding digits",{
Stack:st,Remaining:[k]
})
}
if(k)st.splice(st.length-k,k);
return st.join("").replace(/^0+/,"")||"0"
};