Rakuten interview question

question based on stacks and arrays