Rakuten Interview Question

question based on stacks and arrays