Q9 /20 Mr.
Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.
/20
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 describes a Last-In-First-Out (LIFO) behavior: the car that parked last must leave first before earlier cars can exit. This is the defining characteristic of a stack data structure. A queue (FIFO) would be incorrect because it would allow the first car to leave first, which contradicts the constraint that later cars must leave before earlier ones.
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 arrives and parks
- Car 2 arrives and parks (behind Car 1)
- Car 3 arrives and parks (behind Car 2)
- For Car 1 to leave, Cars 3 and 2 must leave first → Last-In-First-Out (LIFO)
Compare data structures:
- Stack (LIFO): Last element added is first to be removed ✓ Matches the constraint
- Queue (FIFO): First element added is first to be removed ✗ Doesn't match
- Heap: Priority-based ordering ✗ Not applicable
- Linked list: Generic sequential structure without enforced removal order ✗ Not specific
The answer is Stack (A).