""" 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()
""" 1662.1 - Check If Two String Arrays are Equivalent - Solution 1 - String Concatenation """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
"""Check If Two String Arrays are Equivalent"""
return "".join(word1) == "".join(word2)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().arrayStringsAreEqual(["ab", "c"], ["a", "bc"])) # True
print(Solution().arrayStringsAreEqual(["a", "cb"], ["ab", "c"])) # False
print(Solution().arrayStringsAreEqual(["abc", "d", "defg"], ["abcddefg"])) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1662.2 - Check If Two String Arrays are Equivalent - Solution 2 - Two Pointer """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
"""Check If Two String Arrays are Equivalent"""
w1, c1 = 0, 0 # word index and char index for word1
w2, c2 = 0, 0 # word index and char index for word2
while w1 < len(word1) and w2 < len(word2):
if word1[w1][c1] != word2[w2][c2]:
return False
# Advance char pointer for word1
c1 += 1
if c1 == len(word1[w1]):
w1 += 1
c1 = 0
# Advance char pointer for word2
c2 += 1
if c2 == len(word2[w2]):
w2 += 1
c2 = 0
# Both arrays must be fully consumed
return w1 == len(word1) and w2 == len(word2)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().arrayStringsAreEqual(["ab", "c"], ["a", "bc"])) # True
print(Solution().arrayStringsAreEqual(["a", "cb"], ["ab", "c"])) # False
print(Solution().arrayStringsAreEqual(["abc", "d", "defg"], ["abcddefg"])) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()