Design Parking System | Optimized Solution | Daily Leetcode Challenge
\nclass ParkingSystem {\nprivate:\n    int availableSlots[4]; // Array to store available slots for each car type (index 0 is not used)\n\npublic:\n    ParkingS
```\nclass ParkingSystem {\nprivate:\n    int availableSlots[4]; // Array to store available slots for each car type (index 0 is not used)\n\npublic:\n    ParkingSystem(int big, int medium, int small) {\n        availableSlots[1] = big; // Initialize available slots for big cars\n        availableSlots[2] = medium; // Initialize available slots for medium cars\n        availableSlots[3] = small; // Initialize available slots for small cars\n    }\n\n    bool addCar(int carType) {\n        if (availableSlots[carType] > 0) { // If there is an available slot for the given car type\n            availableSlots[carType]--; // Decrement the available slot count for that car type\n            return true; // Return true to indicate successful parking\n        }\n        return false; // Return false if there are no available slots for the given car type\n    }\n};\n```\n\n**Explanation:**\n\nThe ParkingSystem class is defined with private member variable availableSlots, which is an array to store the number of available slots for each car type. The index 0 is not used, and index 1 represents the big car slots, index 2 represents the medium car slots, and index 3 represents the small car slots.\n\nThe constructor ParkingSystem(int big, int medium, int small) initializes the availableSlots array with the given number of slots for each car type.\n\nThe addCar function takes an integer parameter carType, which represents the type of car trying to park. It checks if there is an available slot for the given car type in the parking lot.\n\nIf there is an available slot (availableSlots[carType] > 0), it means the car can be parked. In this case, the function decrements the available slot count for that car type (availableSlots[carType]--) and returns true to indicate that the car has been parked successfully.\n\nIf there are no available slots for the given car type, the function returns false to indicate that the car cannot be parked.\n\n**Complexity Analysis**\n\nThe ParkingSystem constructor has a time complexity of O(1) because it initializes the availableSlots array with the given values, which takes constant time regardless of the input size.\n\nThe addCar function has a time complexity of O(1) as well. It simply checks if there is an available slot for the given car type by accessing the corresponding element in the availableSlots array, which is a constant-time operation. The function then either decrements the available slot count or returns false, both of which are also constant-time operations.\n\nThe space complexity of the solution is O(1) because the space used is independent of the input size. The availableSlots array has a fixed size of 4, regardless of the number of parking slots or car types.\n\nIn summary, the time complexity of the solution is O(1) for both the constructor and the addCar function, and the space complexity is O(1). This implementation provides a constant-time solution for checking and managing parking slots based on the car type.\n\n**PLEASE UPVOTE :)**
['C']