2 ms·
I have a novel solution: use a delta ~~queue~~ stack! Instead of pushing straight numbers, push the delta of each new value against the next smaller value cur
by api_or_ipa 10y ago
I have a novel solution: use a delta ~~queue~~ stack! Instead of pushing straight numbers, push the delta of each new value against the next smaller value currently in the stack. Sadly I can't find a resource for this data structure. I learned about it in university when writing a sleep() function for an OS I was writing. On each tick, you simply decrement the first value (or pop it if it's 0).
[]
push(1) : [1]
push(2) : [1,1]
push(3) : [1,1,1]
push(3) : [1,1,1,0]
pop() : 3, [1,1,1]
pop() : 3, [1,1]
pop() : 2, [1]
pop() : 1 [0]