diff --git a/src/my_project/interviews/google_top_exercises/round_1/03_container_with_most_water.py b/src/my_project/interviews/google_top_exercises/round_1/03_container_with_most_water.py new file mode 100644 index 00000000..4f7f9218 --- /dev/null +++ b/src/my_project/interviews/google_top_exercises/round_1/03_container_with_most_water.py @@ -0,0 +1,22 @@ +from typing import List + +class Solution: + def maxArea(self, height: List[int]) -> int: + left = 0 + right = len(height) - 1 + max_area = 0 + + while left < right: + # Calculate current area + width = right - left + current_height = min(height[left], height[right]) + current_area = width * current_height + max_area = max(max_area, current_area) + + # Move pointer with shorter height + if height[left] < height[right]: + left += 1 + else: + right -= 1 + + return max_area \ No newline at end of file diff --git a/src/my_project/interviews/google_top_exercises/round_1/04_subarray_sum_equals_k.py b/src/my_project/interviews/google_top_exercises/round_1/04_subarray_sum_equals_k.py new file mode 100644 index 00000000..75cc0ed7 --- /dev/null +++ b/src/my_project/interviews/google_top_exercises/round_1/04_subarray_sum_equals_k.py @@ -0,0 +1,15 @@ +from typing import List + +class Solution: + def subarraySum(self, nums: List[int], k: int) -> int: + + answer = 0 + dp = {0:1} + acc = 0 + + for num in nums: + acc += num + answer += dp.get(acc - k, 0) + dp[acc] = dp.get(acc, 0) + 1 + + return answer \ No newline at end of file