I came across this problem in an interview website. The problem asks for efficiently implement three stacks in a single array, such that no stack overflows until there is no
A rather silly but effective solution could be:
i*3 positions: 0,3,6,...i*3+1 positions: 1,4,7...i*3+2 positions.The problem with this solution is that the used memory will be always three times the size of the deepest stack and that you can overflow even when there are available positions at the array.