News for hackers. Stuff that matters.
Re:Ask HN: What are the best interview questions you've been... by api_or_ipa on Wednesday February 22, 2017 @02:47AM (#13703919)
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]

There are no comments on this comment yet.