""" 0001.1 - Solution 1 - Brute Force Approach """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def twoSum(self, nums: List[int], target: int) -> List[int]:
"""Two Sum Function"""
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().twoSum([3, 3], 6))
print(Solution().twoSum([3, 2, 4], 6))
print(Solution().twoSum([2, 7, 11, 15], 9))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0001.1 - Solution 1 - Using Enumerate """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def twoSum(self, nums: List[int], target: int) -> List[int]:
"""Two Sum Function"""
for key1, num1 in enumerate(nums):
for key2, num2 in enumerate(nums[key1 + 1 :], key1 + 1):
# enumerate(iterable, start=1) -> start value determines starting index
# Printing value and key will output 1 i , 2 j, 3 k, 4 l
if num1 + num2 == target:
return [key1, key2]
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().twoSum([3, 3], 6))
print(Solution().twoSum([3, 2, 4], 6))
print(Solution().twoSum([2, 7, 11, 15], 9))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1603.1 - Design Parking System - Solution 1 - Array Approach """
#####################################################################################
# Classes
#####################################################################################
class ParkingSystem:
"""Parking System Class"""
def __init__(self, big: int, medium: int, small: int):
"""Initialize parking system with slot counts for each size."""
self.spaces = [big, medium, small]
def addCar(self, carType: int) -> bool:
"""Attempt to park a car of the given type. Returns True if successful."""
if self.spaces[carType - 1] > 0:
self.spaces[carType - 1] -= 1
return True
return False
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
ps = ParkingSystem(1, 1, 0)
print(ps.addCar(1)) # True
print(ps.addCar(2)) # True
print(ps.addCar(3)) # False
print(ps.addCar(1)) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1603.2 - Design Parking System - Solution 2 - Dictionary Approach """
#####################################################################################
# Classes
#####################################################################################
class ParkingSystem:
"""Parking System Class"""
def __init__(self, big: int, medium: int, small: int):
"""Initialize parking system with a dictionary mapping type to slots."""
self.slots = {1: big, 2: medium, 3: small}
def addCar(self, carType: int) -> bool:
"""Attempt to park a car of the given type. Returns True if successful."""
if self.slots[carType] > 0:
self.slots[carType] -= 1
return True
return False
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
ps = ParkingSystem(1, 1, 0)
print(ps.addCar(1)) # True
print(ps.addCar(2)) # True
print(ps.addCar(3)) # False
print(ps.addCar(1)) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()