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

Q9 /20 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 is a classic Last-In-First-Out (LIFO) scenario. Cars parked later must leave before cars parked earlier can exit—the last car to arrive is the first to leave. A stack perfectly models this behavior. A queue would allow the first car to leave first (FIFO), which contradicts the parking lot constraint. Heaps and linked lists are not designed to enforce this ordering principle.

Step-by-step Derivation:
Analyze the parking lot constraint: 'Once you park, you cannot leave until all cars that came after you leave.' This means if Car A parks first, then Car B parks second, Car B must leave before Car A can leave. This is LIFO ordering:

  • Insert order: A, B, C
  • Exit order: C, B, A (reverse order)
    This matches stack behavior exactly. In contrast, a queue would exit in order A, B, C (FIFO), which violates the constraint.