Mr.
Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Mr. Aoki is planning to visit the shrine for New Years. However, the parking lot at the shrine is very small. Once you park your car, you cannot leave until all of the cars that came after you leave. Choose the data structure that best represents the situation in this parking lot.
Show answer & explanation
This parking lot scenario is a Last-In-First-Out (LIFO) structure. The first car to arrive cannot leave until all subsequent cars have left, meaning the most recently parked car must leave first. This is the defining characteristic of a stack data structure.
Step-by-step Derivation:
Analyze the constraint: 'you cannot leave until all of the cars that came after you leave.' This means if car A parks first and car B parks second, car B must leave before car A can leave. Car C (arriving third) must leave before either A or B. The order of departure is: C, B, A (reverse of arrival order). This is LIFO behavior, which is a stack. A queue would be FIFO (first-in-first-out), which would require the first car to leave first—the opposite of what the problem states. A heap is a priority-based structure, and a linked list is just a data organization method without inherent ordering constraints. Therefore, stack is the correct answer.