Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Problem Statement
Java implementation
Frequently Asked Questions 
Can we avoid using nested IF-ELSE to solve the Design Parking System problem?
Are there other variations of the Design Parking System problem?
Last Updated: Mar 27, 2024

Design Parking System

Roadmap to SDE career at Amazon
Anubhav Sinha
SDE-2 @
25 Jun, 2024 @ 01:30 PM


Design Parking System problem is an easy difficulty question that has been asked in a few competitive coding platforms. The problem can be solved using various techniques in different languages. This article will discuss one of the most straightforward Java implementations of the Design Parking System.

Problem Statement

In this problem, we have to design a parking system for a parking lot. The parking system can contain three types of cars- big, medium,  and small. We have to implement the class ParkingSystem with the following constraints:

  • ParkingSystem(int big, int medium, int small): Constructor that takes the maximum limit of each car type that can be kept in the parking lot. Initialize the objects of the class with the incoming values.
  • bool addCar(int carType): takes the type of car that needs to be added into the parking lot as an argument. The valid inputs for this function can be only one, two, and three. Any other value is not accepted. If a car can be added to the parking lot, return true. If no space is available in the parking lot, then return false.

Example and Explanation





[true, true, true, true, false, false]

In the input, we initialize the constructor with the values- [1, 2, 1]. This means that our parking lot can contain one big car, two medium cars, and one small car. We also pass the values [1, 2, 2, 3, 1, 2] to our addCar function. This means that we want to park two big cars, three medium cars and one small car in our parking lot. 

The output obtained displays whether the car type can be parked or not. So, the cars that can be parked are:

  • The first big car.
  • The following two medium cars.
  • The next small car.

The car that cannot be kept are:

  • The second big car.
  • The third medium car.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job


The implementation in this article is done in Java. As asked in the question, we will create a constructor named ParkingSystem(big(int), medium(int), small(int)). We will create three global variables, namely big, medium, and small. The constructor will initialize the global variables with the incoming values. 

We will create a function boolean addCar(carType(int)). The function will take the values one, two, or three representing the car types- big, medium, or small. On getting a valid car type, we will reduce the corresponding car parking space by one and return true. As long as there is space in our parking lot, we will add cars. If there is no space in the parking lot, we will return false.

Recommended: Try to code the Design Parking System yourself first before proceeding to the solution code.

Java implementation

//Simple Java implementation of
//Design Parking System 
class ParkingSystem {
  public int big,medium,small ;

  public ParkingSystem(int big, int medium, int small) {
      this.big = big;
      this.medium = medium;
      this.small = small;

  public boolean addCar(int carType) {
      if(carType == 1 && big > 0){
          return true;
      if(carType == 2 && medium > 0){
          return true;
      if(carType == 3 && small > 0){
          return true;
      return false;

  public static void main(String[] args){
      ParkingSystem obj1 =new ParkingSystem(1,2,1);
      System.out.print(obj1.addCar(1) + " ");    //first big car
      System.out.print(obj1.addCar(2) + " ");    //first medium car
      System.out.print(obj1.addCar(2) + " ");    //second medium car
      System.out.print(obj1.addCar(3) + " ");    //first small car
      System.out.print(obj1.addCar(1) + " ");    //second big car 
      System.out.print(obj1.addCar(2) + " ");    //third medium car 


true true true true false false 


Time Complexity

In the given implementation, simple if-else checks are used, which have a constant run time. Thus, the time complexity is, T(n) = O(1)

Space Complexity

In the given implementation, no extra space is required for the code to run. Thus, Space complexity = O(1) 

Frequently Asked Questions 

Can we avoid using nested IF-ELSE to solve the Design Parking System problem?

Yes, we can do so. We can create an array of size 3, and initialize the values with the incoming parking lot sizes. In the addCar() function, simply decrease the value at arr[carType] by showing that a car has been added.

Are there other variations of the Design Parking System problem?

Yes, there are a few other variations of the Design Parking System problem. One of them is keeping track of the incoming and outgoing cars and the time for which they have parked. The total time can find the amount the driver has to pay to use the parking lot.


To summarize the article, we thoroughly discussed the Design Parking System problem. We saw the problem statement, an example with the explanation. We also saw one of the approaches and its corresponding code in Java. Finally, we concluded with some FAQs.

Want to ace the coding rounds of big tech companies? Try our Attempt Unlimited Online Mock Test Series to start your preparation.

Learn various topics from Web Technologies, Programming Fundamentals, Data Structures, and Algorithms from our Library.

Recommended Reading:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

You can also consider our System Design Course to give your career an edge over others.

Happy Coding!

Previous article
Double the first element and move zero to the end
Next article
Replace two consecutive equal values with one greater value
Live masterclass