Capgemini interview question

Array related in stack and query too!!