Skip to content

Instantly share code, notes, and snippets.

@amarjitdhillon
Created February 10, 2022 17:10
Show Gist options
  • Save amarjitdhillon/9282430053b80f7fc5eeeb25b4d315ca to your computer and use it in GitHub Desktop.
Save amarjitdhillon/9282430053b80f7fc5eeeb25b4d315ca to your computer and use it in GitHub Desktop.
Design Parking System
class ParkingSystem:
# initialize the parking object
def __init__(self, big: int, medium: int, small: int):
# to hold various types of parking we are using a dict in constructor
self.lot = {}
# add the parking counters in this lot dict
self.lot[1] = big
self.lot[2] = medium
self.lot[3] = small
# if car can be parked then return True else False
def addCar(self, carType: int) -> bool:
# if it has the space, then park the car and update the space
if self.lot.get(carType) > 0:
self.lot[carType] -= 1
return True
else:
# return False if car can not be parked
return False
# Your ParkingSystem object will be instantiated and called as such:
# obj = ParkingSystem(big, medium, small)
# param_1 = obj.addCar(carType)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment