Parking Spots

In this question, we ask you to design a system for a parking lot to keep track of the cars parked in the parking slots. You must design the system in a way that is easily expandable.

This question will come in parts, and you need to answer the previous part before moving on. You are advised to copy the code from the previous section to be used as a starting point for the next.

Part One

A car can be represented as <size> <color> <brand>. For example, "Small Silver BMW", "Large Black Nissan" are all valid car representations. All the allowed sizes are "Small", "Medium", and "Large".

In this parking lot you are given the number of parking slots available at the start, labelled from 0 to n - 1. Your system must support the following commands:

  • "park [spot] [car]": Attempt to park the car into the given spot. If the given spot is unavailable (because a car cannot park there, or there is already a car), the car will try to park in the next available spot in order until it finds an available slot, or there are no more slots left (in which case the car leaves the parking lot).
  • "remove [spot]": Remove the car parked at that spot. Do nothing if there is no car there.
  • "print [spot]": Print the representation of the car at that spot, or "Empty" if that spot is empty.
  • "print_free_spots": Print the number of slots free in the parking lot.


  • n: The number of slots in the parking lot.
  • instructions: A string matrix representing the instructions.


A list of strings representing the printed output.


Example 1


1n = 5
2instructions = [
3  ["park", "1", "Small", "Silver", "BMW"],
4  ["park", "1", "Large", "Black", "Nissan"],
5  ["print", "1"],
6  ["print", "2"],
7  ["print", "3"],


2  "Small Silver BMW",
3  "Large Black Nissan",
4  "Empty",

Try it yourself


↑TA πŸ‘¨β€πŸ«