[Simulation Tutorial] Design Parking System
Topic :  Simulation\n___\n\n## Solution\nCreate an array of size 4 to represent the available space for each type of car. In the addCar function, verify if ther
**Topic** :  Simulation\n___\n\n## Solution\nCreate an array of size 4 to represent the available space for each type of car. In the `addCar` function, verify if there is sufficient space for the specified car type. If space is available, decrement the count by 1 and return true; otherwise, return false.\n\n\n<br/><br/>\n\n```c++ []\nclass ParkingSystem {\npublic:\n    vector<int> space;\n    ParkingSystem(int big, int medium, int small) {\n        space = {0, big, medium, small};\n    }\n    \n    bool addCar(int carType) {\n        return space[carType]-- > 0;\n    }\n};\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem* obj = new ParkingSystem(big, medium, small);\n * bool param_1 = obj->addCar(carType);\n */\n```\n```Java []\nclass ParkingSystem {\n    int[] space;\n    public ParkingSystem(int big, int medium, int small) {\n        space = new int[]{0, big, medium, small};\n    }\n    \n    public boolean addCar(int carType) {\n        return space[carType]-- > 0;\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```\n```Python []\nclass ParkingSystem:\n\n    def __init__(self, big: int, medium: int, small: int):\n        self.space = [0, big, medium, small]\n\n    def addCar(self, carType: int) -> bool:\n        if self.space[carType] > 0:\n            self.space[carType] -= 1\n            return True\n        else:\n            return False\n\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem(big, medium, small)\n# param_1 = obj.addCar(carType)\n```\n```Go []\ntype ParkingSystem struct {\n    space []int\n}\n\n\nfunc Constructor(big int, medium int, small int) ParkingSystem {\n     return ParkingSystem{[]int{0, big, medium, small}}\n}\n\n\nfunc (this *ParkingSystem) AddCar(carType int) bool {\n    if this.space[carType] > 0 {\n        this.space[carType]--\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 * obj := Constructor(big, medium, small);\n * param_1 := obj.AddCar(carType);\n */\n```\n```PHP []\nclass ParkingSystem {\n    /**\n     * @param Integer $big\n     * @param Integer $medium\n     * @param Integer $small\n     */\n    private $space;\n    function __construct($big, $medium, $small) {\n        $this->space = array(0, $big, $medium, $small);\n    }\n  \n    /**\n     * @param Integer $carType\n     * @return Boolean\n     */\n    function addCar($carType) {\n        if ($this->space[$carType] > 0) {\n            $this->space[$carType]--;\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 * $obj = ParkingSystem($big, $medium, $small);\n * $ret_1 = $obj->addCar($carType);\n */\n```\n```Javascript []\n/**\n * @param {number} big\n * @param {number} medium\n * @param {number} small\n */\nvar ParkingSystem = function(big, medium, small) {\n    this.space = [0, big, medium, small];\n};\n\n/** \n * @param {number} carType\n * @return {boolean}\n */\nParkingSystem.prototype.addCar = function(carType) {\n    if (this.space[carType] > 0) {\n        this.space[carType]--;\n        return true;\n    } else {\n        return false;\n    }\n};\n\n/** \n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */\n```\n\n\n**Complexity**:\n* Time Complexity : `O(1)` per call.\n* Space Complexity : `O(1)`\n\n**Feel free to leave a comment if something is confusing, or if you have any suggestions on how I can improve the post.**
['PHP', 'Python', 'Java', 'Go', 'JavaScript']