From 4cfddbdd3dea4d2e053b71a517008d90ad4d467c Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 4 Aug 2026 05:25:48 -0600 Subject: [PATCH] adding updates --- ...maximum_sum_distinct_subarrays_lenght_k.py | 25 +++++++++++++++++++ .../round_1/28_alien_dictionary.py | 9 +++++++ 2 files changed, 34 insertions(+) create mode 100644 src/my_project/interviews/amazon_high_frequency_23/round_7/maximum_sum_distinct_subarrays_lenght_k.py diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_7/maximum_sum_distinct_subarrays_lenght_k.py b/src/my_project/interviews/amazon_high_frequency_23/round_7/maximum_sum_distinct_subarrays_lenght_k.py new file mode 100644 index 00000000..d84f09e4 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_7/maximum_sum_distinct_subarrays_lenght_k.py @@ -0,0 +1,25 @@ +from typing import List, Union, Collection, Mapping, Optional + +class Solution: + def maximumSubarraySum(self, nums: List[int], k: int) -> int: + max_sum = 0 + current_sum = 0 + freq = {} + left = 0 + + for right in range(len(nums)): + current_sum += nums[right] + + freq[nums[right]] = freq.get(nums[right], 0) + 1 + + if right - left > k - 1: + freq[nums[left]] -= 1 + if freq[nums[left]] == 0: + del freq[nums[left]] + current_sum -= nums[left] + left += 1 + + if right - left == k - 1 and len(freq) == k: + max_sum = max(max_sum, current_sum) + + return max_sum diff --git a/src/my_project/interviews/google_top_exercises/round_1/28_alien_dictionary.py b/src/my_project/interviews/google_top_exercises/round_1/28_alien_dictionary.py index c141f2c2..bee6c0f2 100644 --- a/src/my_project/interviews/google_top_exercises/round_1/28_alien_dictionary.py +++ b/src/my_project/interviews/google_top_exercises/round_1/28_alien_dictionary.py @@ -57,8 +57,11 @@ def alienOrder_DFS(self, words: List[str]) -> str: adj = defaultdict(set) letters = {c for word in words for c in word} + print(list(zip(words, words[1:]))) for first, second in zip(words, words[1:]): for c1, c2 in zip(first, second): + print(list(zip(first,second))) + print(c1,c2) if c1 != c2: adj[c1].add(c2) break @@ -66,6 +69,8 @@ def alienOrder_DFS(self, words: List[str]) -> str: if len(second) < len(first): return "" + print(adj) + visiting = {} order = [] @@ -88,3 +93,7 @@ def dfs(c: str) -> bool: return "" return "".join(reversed(order)) + + +solution = Solution() +print(solution.alienOrder_DFS(words = ["wrt","wrf","er","ett","rftt"])) \ No newline at end of file