← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design a parking lot system with these core operations:
park(vehicle)unpark(license_plate)check_car(license_plate)The main constraint is the spot compatibility rule:
MOTORCYCLE spot can only be occupied by a MOTORCYCLE vehicle.CAR spot can be occupied by any type of vehicle.MOTORCYCLE and CAR spots.MOTORCYCLE vehicle can park in either a MOTORCYCLE or CAR spot.CAR vehicle can only park in a CAR spot.MOTORCYCLE vehicle arrives, it should be parked in the first available MOTORCYCLE spot. If no MOTORCYCLE spot is available, it should be parked in the first available CAR spot.CAR vehicle arrives, it should be parked in the first available CAR spot.Here's a possible solution outline for the Design Parking Lot problem:
Spot class with properties like spot_type (MOTORCYCLE or CAR) and is_occupied.ParkingLot class with a list of Spot objects and methods like park(vehicle), unpark(license_plate), and check_car(license_plate).park(vehicle) method, find the first available spot that matches the vehicle type and mark it as occupied.unpark(license_plate) method, find the spot with the given license plate, mark it as unoccupied, and update the vehicle's state.check_car(license_plate) method, find the spot with the given license plate and return its state (parked or not).`python class Spot: def init(self, spot_type): self.spot_type = spot_type self.is_occupied = False
class ParkingLot: def init(self, num_motorcycle_spots, num_car_spots): self.spots = [Spot("MOTORCYCLE") for _ in range(num_motorcycle_spots)] + [Spot("CAR") for _ in range(num_car_spots)]
def park(self, vehicle):
# Find the first available spot that matches the vehicle type and mark it as occupied
pass
def unpark(self, license_plate):
# Find the spot with the given license plate, mark it as unoccupied, and update the vehicle's state
pass
def check_car(self, license_plate):
# Find the spot with the given license_plate and return its state (parked or not)
pass
`
This is a high-level solution outline. You can implement the specific logic for each method based on the problem requirements and constraints.