Java Solution for Design Parking System Problem
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the above solution is to keep track of the available slots for eac
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the above solution is to keep track of the available slots for each type of car (big, medium, small) and determine if a car can be parked based on its type and the availability of slots.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is to use instance variables bigSlots, mediumSlots, and smallSlots to store the number of available slots for each car type. When the addCar method is called, it checks the car type and available slots for that type. If there are available slots, it decrements the corresponding slot count and returns true. Otherwise, it returns false.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of the addCar method is constant, O(1), because the decision-making process is based on simple conditions and does not involve any iteration or recursion.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity is also constant, as it only requires a few additional variables to store the slot counts.\n\n# Code\n```\nclass ParkingSystem {\n    private int bigSlots;\n    private int mediumSlots;\n    private int smallSlots;\n    public ParkingSystem(int big, int medium, int small) {\n        bigSlots = big;\n        mediumSlots = medium;\n        smallSlots = small;  \n    }\n    \n    public boolean addCar(int carType) {\n         if (carType == 1 && bigSlots > 0) {\n            bigSlots--;\n            return true;\n        } else if (carType == 2 && mediumSlots > 0) {\n            mediumSlots--;\n            return true;\n        } else if (carType == 3 && smallSlots > 0) {\n            smallSlots--;\n            return true;\n        } else {\n            return false;\n        }\n    }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem obj = new ParkingSystem(big, medium, small);\n * boolean param_1 = obj.addCar(carType);\n */\n```
['Java']