OA. free
Free
Accenture Core Computer Science Core Computer Science Medium

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.

Choose one option.
Show answer & explanation
Answer: A. stack

This parking lot follows Last-In-First-Out (LIFO) behavior, which is the defining characteristic of a stack. The car that arrived last (parked most recently) must leave first before any cars parked before it can exit. A queue operates on FIFO (First-In-First-Out), which is the opposite of this scenario. A heap is a tree-based structure used for priority-based ordering, and a linked list is a sequential data structure without this blocking constraint.

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 arrived first and car B arrived second, car B must leave before car A can leave. This is LIFO behavior:

  • Car 1 arrives (parked)
  • Car 2 arrives (parked on top)
  • Car 3 arrives (parked on top)
  • Car 3 must leave first
  • Then Car 2 can leave
  • Finally Car 1 can leave
    This sequence (last in, first out) matches the stack data structure perfectly.