implement memory efficient k stacks in on array