""" 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()
""" 1189.1 - Maximum Number of Balloons - Solution 1 - Counter Approach """
#####################################################################################
# Imports
#####################################################################################
from collections import Counter
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def maxNumberOfBalloons(self, text: str) -> int:
"""Maximum Number of Balloons Function"""
count_text = Counter(text)
balloon = Counter("balloon")
res = len(text)
for c in balloon:
res = min(res, count_text[c] // balloon[c])
return res
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().maxNumberOfBalloons("nlaebolko")) # 1
print(Solution().maxNumberOfBalloons("loonbalxballpoon")) # 2
print(Solution().maxNumberOfBalloons("leetcode")) # 0
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1189.2 - Maximum Number of Balloons - Solution 2 - Manual Character Count """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def maxNumberOfBalloons(self, text: str) -> int:
"""Maximum Number of Balloons Function"""
count_b = 0
count_a = 0
count_l = 0
count_o = 0
count_n = 0
for c in text:
if c == 'b':
count_b += 1
elif c == 'a':
count_a += 1
elif c == 'l':
count_l += 1
elif c == 'o':
count_o += 1
elif c == 'n':
count_n += 1
return min(count_b, count_a, count_l // 2, count_o // 2, count_n)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().maxNumberOfBalloons("nlaebolko")) # 1
print(Solution().maxNumberOfBalloons("loonbalxballpoon")) # 2
print(Solution().maxNumberOfBalloons("leetcode")) # 0
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()