LeetCode Entry
1603. Design Parking System
Return if car of type 1, 2 or 3 can be added given sizes big, medium and small.
1603. Design Parking System easy blog post substack
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/227
Problem TLDR
Return if car of type 1, 2 or 3 can be added given sizes big, medium and small.
Intuition
Just write the code.
Approach
Let’s use an array to minimize the number of lines.
Complexity
- Time complexity: \(O(1)\)
- Space complexity: \(O(1)\)
Code
class ParkingSystem(big: Int, medium: Int, small: Int) {
val types = arrayOf(big, medium, small)
fun addCar(carType: Int): Boolean = types[carType - 1]-- > 0
}