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 Year's. 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 represents a Last-In-First-Out (LIFO) behavior: the most recently parked car (last to arrive) must leave first before any car that parked before it can leave. This is the defining characteristic of a stack data structure. A queue would be FIFO (first in, first out), which is the opposite of this constraint. A heap is a priority-based structure, and a linked list is merely a storage structure without this ordering constraint.
Step-by-step Derivation:
Analyze the constraint: 'Once you park your car, you cannot leave until all of the cars that came after you leave.' This means:
- Car 1 parks (bottom)
- Car 2 parks (on top of Car 1)
- Car 3 parks (on top of Car 2)
- To leave: Car 3 must leave first, then Car 2, then Car 1
This is Last-In-First-Out (LIFO) = Stack behavior.
Contrast with queue (FIFO): Car 1 would leave first, but that violates the constraint.
Therefore, the answer is Stack (A).