From eca9bb298dd8dc1a1b00ed1729b4046c3d80461f Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Thu, 9 Oct 2025 20:15:23 +0530 Subject: [PATCH 01/13] added 3 DSA questions in python --- data_structures/arrays/fruit_into_baskets.py | 40 +++++++++++++++ .../arrays/longest_ones_after_replacement.py | 39 ++++++++++++++ .../arrays/sliding_window_maximum.py | 51 +++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 data_structures/arrays/fruit_into_baskets.py create mode 100644 data_structures/arrays/longest_ones_after_replacement.py create mode 100644 data_structures/arrays/sliding_window_maximum.py diff --git a/data_structures/arrays/fruit_into_baskets.py b/data_structures/arrays/fruit_into_baskets.py new file mode 100644 index 000000000000..c2c596380c74 --- /dev/null +++ b/data_structures/arrays/fruit_into_baskets.py @@ -0,0 +1,40 @@ +""" +Question: +Given an array fruits representing types of fruit, pick a contiguous subarray containing at most 2 different types of fruit. +Return the maximum number of fruits you can collect. + +Example: +Input: fruits = [1,2,1,2,3] +Output: 4 +Explanation: +Pick subarray [1,2,1,2] -> contains 2 types and length 4 +""" + +from typing import List +from collections import defaultdict + +class FruitIntoBaskets: + def total_fruit(self, fruits: List[int]) -> int: + count = defaultdict(int) # Stores count of each fruit type + left = 0 # Left pointer of sliding window + max_fruit = 0 # Tracks max number of fruits collected + + for right, fruit in enumerate(fruits): + count[fruit] += 1 # Include current fruit + + # Shrink window if more than 2 types + while len(count) > 2: + count[fruits[left]] -= 1 + if count[fruits[left]] == 0: + del count[fruits[left]] + left += 1 + + max_fruit = max(max_fruit, right - left + 1) + + return max_fruit + +# Example dry run +if __name__ == "__main__": + fruits = [1,2,1,2,3] + solver = FruitIntoBaskets() + print("Maximum Fruits Collected:", solver.total_fruit(fruits)) diff --git a/data_structures/arrays/longest_ones_after_replacement.py b/data_structures/arrays/longest_ones_after_replacement.py new file mode 100644 index 000000000000..5fb94bce6aeb --- /dev/null +++ b/data_structures/arrays/longest_ones_after_replacement.py @@ -0,0 +1,39 @@ +""" +Question: +Given a binary array nums and an integer k, find the length of the longest subarray containing 1s after flipping at most k zeros. + +Example: +Input: nums = [1,0,1,1,0,1], k = 1 +Output: 4 +Explanation: +Flip the first 0 at index 1 -> subarray [1,1,1,1] has length 4 +""" + +from typing import List + +class LongestOnesAfterReplacement: + def longest_ones(self, nums: List[int], k: int) -> int: + left = 0 # Left pointer of sliding window + max_len = 0 # Tracks maximum window length + zeros_count = 0 # Count of zeros in current window + + for right in range(len(nums)): + if nums[right] == 0: + zeros_count += 1 + + # Shrink window if zeros exceed k + while zeros_count > k: + if nums[left] == 0: + zeros_count -= 1 + left += 1 + + max_len = max(max_len, right - left + 1) + + return max_len + +# Example dry run +if __name__ == "__main__": + nums = [1,0,1,1,0,1] + k = 1 + solver = LongestOnesAfterReplacement() + print("Longest Ones After Replacement:", solver.longest_ones(nums, k)) diff --git a/data_structures/arrays/sliding_window_maximum.py b/data_structures/arrays/sliding_window_maximum.py new file mode 100644 index 000000000000..f63e6e185bc3 --- /dev/null +++ b/data_structures/arrays/sliding_window_maximum.py @@ -0,0 +1,51 @@ +""" +Question: +Given an integer array nums and an integer k, return the maximum value in each sliding window of size k. + +Example: +Input: nums = [1,3,-1,-3,5,3,6,7], k = 3 +Output: [3,3,5,5,6,7] +Explanation: +Window positions and max values: +[1,3,-1] -> max = 3 +[3,-1,-3] -> max = 3 +[-1,-3,5] -> max = 5 +[-3,5,3] -> max = 5 +[5,3,6] -> max = 6 +[3,6,7] -> max = 7 +""" + +from collections import deque +from typing import List + +class SlidingWindowMaximum: + def max_sliding_window(self, nums: List[int], k: int) -> List[int]: + if not nums: + return [] + + result = [] # Stores max of each window + window = deque() # Stores indices of elements in current window + + for i, num in enumerate(nums): + # Remove indices of elements outside current window + while window and window[0] <= i - k: + window.popleft() + + # Remove indices of elements smaller than current num + while window and nums[window[-1]] < num: + window.pop() + + window.append(i) + + # Add the max for this window to result + if i >= k - 1: + result.append(nums[window[0]]) + + return result + +# Example dry run +if __name__ == "__main__": + nums = [1,3,-1,-3,5,3,6,7] + k = 3 + solver = SlidingWindowMaximum() + print("Sliding Window Maximum:", solver.max_sliding_window(nums, k)) From 6da352fd47b611f377406f5c652dbde78c5a1a37 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 15:33:42 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/fruit_into_baskets.py | 4 +++- data_structures/arrays/longest_ones_after_replacement.py | 4 +++- data_structures/arrays/sliding_window_maximum.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/fruit_into_baskets.py b/data_structures/arrays/fruit_into_baskets.py index c2c596380c74..20484969a636 100644 --- a/data_structures/arrays/fruit_into_baskets.py +++ b/data_structures/arrays/fruit_into_baskets.py @@ -13,6 +13,7 @@ from typing import List from collections import defaultdict + class FruitIntoBaskets: def total_fruit(self, fruits: List[int]) -> int: count = defaultdict(int) # Stores count of each fruit type @@ -33,8 +34,9 @@ def total_fruit(self, fruits: List[int]) -> int: return max_fruit + # Example dry run if __name__ == "__main__": - fruits = [1,2,1,2,3] + fruits = [1, 2, 1, 2, 3] solver = FruitIntoBaskets() print("Maximum Fruits Collected:", solver.total_fruit(fruits)) diff --git a/data_structures/arrays/longest_ones_after_replacement.py b/data_structures/arrays/longest_ones_after_replacement.py index 5fb94bce6aeb..e64cb0b8d779 100644 --- a/data_structures/arrays/longest_ones_after_replacement.py +++ b/data_structures/arrays/longest_ones_after_replacement.py @@ -11,6 +11,7 @@ from typing import List + class LongestOnesAfterReplacement: def longest_ones(self, nums: List[int], k: int) -> int: left = 0 # Left pointer of sliding window @@ -31,9 +32,10 @@ def longest_ones(self, nums: List[int], k: int) -> int: return max_len + # Example dry run if __name__ == "__main__": - nums = [1,0,1,1,0,1] + nums = [1, 0, 1, 1, 0, 1] k = 1 solver = LongestOnesAfterReplacement() print("Longest Ones After Replacement:", solver.longest_ones(nums, k)) diff --git a/data_structures/arrays/sliding_window_maximum.py b/data_structures/arrays/sliding_window_maximum.py index f63e6e185bc3..e9e02ad3cd8c 100644 --- a/data_structures/arrays/sliding_window_maximum.py +++ b/data_structures/arrays/sliding_window_maximum.py @@ -18,6 +18,7 @@ from collections import deque from typing import List + class SlidingWindowMaximum: def max_sliding_window(self, nums: List[int], k: int) -> List[int]: if not nums: @@ -43,9 +44,10 @@ def max_sliding_window(self, nums: List[int], k: int) -> List[int]: return result + # Example dry run if __name__ == "__main__": - nums = [1,3,-1,-3,5,3,6,7] + nums = [1, 3, -1, -3, 5, 3, 6, 7] k = 3 solver = SlidingWindowMaximum() print("Sliding Window Maximum:", solver.max_sliding_window(nums, k)) From 3d2a1a1e9b95f82486643f07bde0b4866c0b97d0 Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:15:05 +0530 Subject: [PATCH 03/13] Refactor docstring in FruitIntoBaskets class Updated the class docstring to provide a clearer problem statement and example usage. --- data_structures/arrays/fruit_into_baskets.py | 39 +++++++++----------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/data_structures/arrays/fruit_into_baskets.py b/data_structures/arrays/fruit_into_baskets.py index 20484969a636..5c989bea3a7b 100644 --- a/data_structures/arrays/fruit_into_baskets.py +++ b/data_structures/arrays/fruit_into_baskets.py @@ -1,29 +1,27 @@ -""" -Question: -Given an array fruits representing types of fruit, pick a contiguous subarray containing at most 2 different types of fruit. -Return the maximum number of fruits you can collect. - -Example: -Input: fruits = [1,2,1,2,3] -Output: 4 -Explanation: -Pick subarray [1,2,1,2] -> contains 2 types and length 4 -""" - from typing import List from collections import defaultdict - class FruitIntoBaskets: + """ + Problem: + Given an array of integers representing types of fruit, pick a contiguous subarray + containing at most two different types of fruit. Return the maximum number + of fruits you can collect. + + Example: + >>> solver = FruitIntoBaskets() + >>> solver.total_fruit([1, 2, 1, 2, 3]) + 4 + """ + def total_fruit(self, fruits: List[int]) -> int: - count = defaultdict(int) # Stores count of each fruit type - left = 0 # Left pointer of sliding window - max_fruit = 0 # Tracks max number of fruits collected + count = defaultdict(int) + left = 0 + max_fruit = 0 for right, fruit in enumerate(fruits): - count[fruit] += 1 # Include current fruit + count[fruit] += 1 - # Shrink window if more than 2 types while len(count) > 2: count[fruits[left]] -= 1 if count[fruits[left]] == 0: @@ -35,8 +33,7 @@ def total_fruit(self, fruits: List[int]) -> int: return max_fruit -# Example dry run if __name__ == "__main__": - fruits = [1, 2, 1, 2, 3] solver = FruitIntoBaskets() - print("Maximum Fruits Collected:", solver.total_fruit(fruits)) + print("Maximum Fruits Collected:", solver.total_fruit([1, 2, 1, 2, 3])) + From a43dcaee7b882e54be8924b7028d9aff332af9ea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:45:25 +0000 Subject: [PATCH 04/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/fruit_into_baskets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/arrays/fruit_into_baskets.py b/data_structures/arrays/fruit_into_baskets.py index 5c989bea3a7b..f043f40fa439 100644 --- a/data_structures/arrays/fruit_into_baskets.py +++ b/data_structures/arrays/fruit_into_baskets.py @@ -1,6 +1,7 @@ from typing import List from collections import defaultdict + class FruitIntoBaskets: """ Problem: @@ -36,4 +37,3 @@ def total_fruit(self, fruits: List[int]) -> int: if __name__ == "__main__": solver = FruitIntoBaskets() print("Maximum Fruits Collected:", solver.total_fruit([1, 2, 1, 2, 3])) - From 5755807fbc26f0cc7fc6ef836406ff4d4f357e01 Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:15:53 +0530 Subject: [PATCH 05/13] Refactor longest_ones method and update docstring Updated the problem statement and example in the docstring. Changed parameter name from 'k' to 'max_zero_flips' for clarity. --- .../arrays/longest_ones_after_replacement.py | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/data_structures/arrays/longest_ones_after_replacement.py b/data_structures/arrays/longest_ones_after_replacement.py index e64cb0b8d779..904aa11e910d 100644 --- a/data_structures/arrays/longest_ones_after_replacement.py +++ b/data_structures/arrays/longest_ones_after_replacement.py @@ -1,29 +1,27 @@ -""" -Question: -Given a binary array nums and an integer k, find the length of the longest subarray containing 1s after flipping at most k zeros. - -Example: -Input: nums = [1,0,1,1,0,1], k = 1 -Output: 4 -Explanation: -Flip the first 0 at index 1 -> subarray [1,1,1,1] has length 4 -""" - from typing import List - class LongestOnesAfterReplacement: - def longest_ones(self, nums: List[int], k: int) -> int: - left = 0 # Left pointer of sliding window - max_len = 0 # Tracks maximum window length - zeros_count = 0 # Count of zeros in current window + """ + Problem: + Given a binary array and an integer max_zero_flips, find the length of the + longest subarray containing only 1s after flipping at most max_zero_flips zeros. + + Example: + >>> solver = LongestOnesAfterReplacement() + >>> solver.longest_ones([1, 0, 1, 1, 0, 1], 1) + 4 + """ + + def longest_ones(self, nums: List[int], max_zero_flips: int) -> int: + left = 0 + max_len = 0 + zeros_count = 0 for right in range(len(nums)): if nums[right] == 0: zeros_count += 1 - # Shrink window if zeros exceed k - while zeros_count > k: + while zeros_count > max_zero_flips: if nums[left] == 0: zeros_count -= 1 left += 1 @@ -33,9 +31,8 @@ def longest_ones(self, nums: List[int], k: int) -> int: return max_len -# Example dry run if __name__ == "__main__": - nums = [1, 0, 1, 1, 0, 1] - k = 1 solver = LongestOnesAfterReplacement() - print("Longest Ones After Replacement:", solver.longest_ones(nums, k)) + print("Longest Ones After Replacement:", + solver.longest_ones([1, 0, 1, 1, 0, 1], 1)) + From f53b67d74c3c8c509ba1454771a8b68be83ee7a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:46:13 +0000 Subject: [PATCH 06/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/longest_ones_after_replacement.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/longest_ones_after_replacement.py b/data_structures/arrays/longest_ones_after_replacement.py index 904aa11e910d..adb97b30521f 100644 --- a/data_structures/arrays/longest_ones_after_replacement.py +++ b/data_structures/arrays/longest_ones_after_replacement.py @@ -1,5 +1,6 @@ from typing import List + class LongestOnesAfterReplacement: """ Problem: @@ -33,6 +34,4 @@ def longest_ones(self, nums: List[int], max_zero_flips: int) -> int: if __name__ == "__main__": solver = LongestOnesAfterReplacement() - print("Longest Ones After Replacement:", - solver.longest_ones([1, 0, 1, 1, 0, 1], 1)) - + print("Longest Ones After Replacement:", solver.longest_ones([1, 0, 1, 1, 0, 1], 1)) From 70471932e9be885c4ade27af67731ca4323b9df5 Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:16:22 +0530 Subject: [PATCH 07/13] Refactor sliding window maximum function parameters Updated the method to use 'window_size' instead of 'k' for clarity. Added docstring examples for better understanding. --- .../arrays/sliding_window_maximum.py | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/data_structures/arrays/sliding_window_maximum.py b/data_structures/arrays/sliding_window_maximum.py index e9e02ad3cd8c..7d86bfc4d40f 100644 --- a/data_structures/arrays/sliding_window_maximum.py +++ b/data_structures/arrays/sliding_window_maximum.py @@ -1,53 +1,42 @@ -""" -Question: -Given an integer array nums and an integer k, return the maximum value in each sliding window of size k. - -Example: -Input: nums = [1,3,-1,-3,5,3,6,7], k = 3 -Output: [3,3,5,5,6,7] -Explanation: -Window positions and max values: -[1,3,-1] -> max = 3 -[3,-1,-3] -> max = 3 -[-1,-3,5] -> max = 5 -[-3,5,3] -> max = 5 -[5,3,6] -> max = 6 -[3,6,7] -> max = 7 -""" - from collections import deque from typing import List - class SlidingWindowMaximum: - def max_sliding_window(self, nums: List[int], k: int) -> List[int]: + """ + Problem: + Given an integer array and a window_size, return the maximum value in each + sliding window of that size. + + Example: + >>> solver = SlidingWindowMaximum() + >>> solver.max_sliding_window([1, 3, -1, -3, 5, 3, 6, 7], 3) + [3, 3, 5, 5, 6, 7] + """ + + def max_sliding_window(self, nums: List[int], window_size: int) -> List[int]: if not nums: return [] - result = [] # Stores max of each window - window = deque() # Stores indices of elements in current window + result = [] + window = deque() for i, num in enumerate(nums): - # Remove indices of elements outside current window - while window and window[0] <= i - k: + while window and window[0] <= i - window_size: window.popleft() - # Remove indices of elements smaller than current num while window and nums[window[-1]] < num: window.pop() window.append(i) - # Add the max for this window to result - if i >= k - 1: + if i >= window_size - 1: result.append(nums[window[0]]) return result -# Example dry run if __name__ == "__main__": - nums = [1, 3, -1, -3, 5, 3, 6, 7] - k = 3 solver = SlidingWindowMaximum() - print("Sliding Window Maximum:", solver.max_sliding_window(nums, k)) + print("Sliding Window Maximum:", + solver.max_sliding_window([1, 3, -1, -3, 5, 3, 6, 7], 3)) + From e245324ad0d3a742440e95714485807840e58cee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:46:50 +0000 Subject: [PATCH 08/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/sliding_window_maximum.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/sliding_window_maximum.py b/data_structures/arrays/sliding_window_maximum.py index 7d86bfc4d40f..436bde5dc486 100644 --- a/data_structures/arrays/sliding_window_maximum.py +++ b/data_structures/arrays/sliding_window_maximum.py @@ -1,6 +1,7 @@ from collections import deque from typing import List + class SlidingWindowMaximum: """ Problem: @@ -37,6 +38,7 @@ def max_sliding_window(self, nums: List[int], window_size: int) -> List[int]: if __name__ == "__main__": solver = SlidingWindowMaximum() - print("Sliding Window Maximum:", - solver.max_sliding_window([1, 3, -1, -3, 5, 3, 6, 7], 3)) - + print( + "Sliding Window Maximum:", + solver.max_sliding_window([1, 3, -1, -3, 5, 3, 6, 7], 3), + ) From ccc32fd2c5ceef7ed0cf943a4f921fabfc10bc62 Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:18:06 +0530 Subject: [PATCH 09/13] Refactor total_fruit method parameter type hint Updated type hint for fruits parameter from List[int] to list[int]. --- data_structures/arrays/fruit_into_baskets.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data_structures/arrays/fruit_into_baskets.py b/data_structures/arrays/fruit_into_baskets.py index f043f40fa439..1171a2e82b17 100644 --- a/data_structures/arrays/fruit_into_baskets.py +++ b/data_structures/arrays/fruit_into_baskets.py @@ -1,13 +1,12 @@ -from typing import List from collections import defaultdict class FruitIntoBaskets: """ Problem: - Given an array of integers representing types of fruit, pick a contiguous subarray - containing at most two different types of fruit. Return the maximum number - of fruits you can collect. + Given an array of integers representing types of fruit, pick a contiguous + subarray containing at most two different types of fruit. Return the maximum + number of fruits you can collect. Example: >>> solver = FruitIntoBaskets() @@ -15,7 +14,7 @@ class FruitIntoBaskets: 4 """ - def total_fruit(self, fruits: List[int]) -> int: + def total_fruit(self, fruits: list[int]) -> int: count = defaultdict(int) left = 0 max_fruit = 0 @@ -37,3 +36,4 @@ def total_fruit(self, fruits: List[int]) -> int: if __name__ == "__main__": solver = FruitIntoBaskets() print("Maximum Fruits Collected:", solver.total_fruit([1, 2, 1, 2, 3])) + From 6d7bb8ff326fe5c6f8df4430a52eee40bb9a08fc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:48:26 +0000 Subject: [PATCH 10/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/fruit_into_baskets.py | 1 - 1 file changed, 1 deletion(-) diff --git a/data_structures/arrays/fruit_into_baskets.py b/data_structures/arrays/fruit_into_baskets.py index 1171a2e82b17..a2b5b2554e30 100644 --- a/data_structures/arrays/fruit_into_baskets.py +++ b/data_structures/arrays/fruit_into_baskets.py @@ -36,4 +36,3 @@ def total_fruit(self, fruits: list[int]) -> int: if __name__ == "__main__": solver = FruitIntoBaskets() print("Maximum Fruits Collected:", solver.total_fruit([1, 2, 1, 2, 3])) - From 1b2ccf24c23a4a4cf4765edf0664279244673cc7 Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:19:18 +0530 Subject: [PATCH 11/13] Refactor longest_ones method and improve formatting --- .../arrays/longest_ones_after_replacement.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data_structures/arrays/longest_ones_after_replacement.py b/data_structures/arrays/longest_ones_after_replacement.py index adb97b30521f..8b3cbfc73848 100644 --- a/data_structures/arrays/longest_ones_after_replacement.py +++ b/data_structures/arrays/longest_ones_after_replacement.py @@ -1,11 +1,9 @@ -from typing import List - - class LongestOnesAfterReplacement: """ Problem: Given a binary array and an integer max_zero_flips, find the length of the - longest subarray containing only 1s after flipping at most max_zero_flips zeros. + longest subarray containing only 1s after flipping at most max_zero_flips + zeros. Example: >>> solver = LongestOnesAfterReplacement() @@ -13,7 +11,7 @@ class LongestOnesAfterReplacement: 4 """ - def longest_ones(self, nums: List[int], max_zero_flips: int) -> int: + def longest_ones(self, nums: list[int], max_zero_flips: int) -> int: left = 0 max_len = 0 zeros_count = 0 @@ -34,4 +32,8 @@ def longest_ones(self, nums: List[int], max_zero_flips: int) -> int: if __name__ == "__main__": solver = LongestOnesAfterReplacement() - print("Longest Ones After Replacement:", solver.longest_ones([1, 0, 1, 1, 0, 1], 1)) + print( + "Longest Ones After Replacement:", + solver.longest_ones([1, 0, 1, 1, 0, 1], 1), + ) + From 1515c0279205a99a27d1c40ec556eb8a29b467a7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:49:37 +0000 Subject: [PATCH 12/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/longest_ones_after_replacement.py | 1 - 1 file changed, 1 deletion(-) diff --git a/data_structures/arrays/longest_ones_after_replacement.py b/data_structures/arrays/longest_ones_after_replacement.py index 8b3cbfc73848..a88d3b090c46 100644 --- a/data_structures/arrays/longest_ones_after_replacement.py +++ b/data_structures/arrays/longest_ones_after_replacement.py @@ -36,4 +36,3 @@ def longest_ones(self, nums: list[int], max_zero_flips: int) -> int: "Longest Ones After Replacement:", solver.longest_ones([1, 0, 1, 1, 0, 1], 1), ) - From b7ce1d501d9ed0d80a57a0494d6cdea32384f521 Mon Sep 17 00:00:00 2001 From: Shanmukha Pranav <147685740+PranavKuruvella@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:19:47 +0530 Subject: [PATCH 13/13] Update type hints to use built-in list type --- data_structures/arrays/sliding_window_maximum.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/data_structures/arrays/sliding_window_maximum.py b/data_structures/arrays/sliding_window_maximum.py index 436bde5dc486..4287f4e9af5f 100644 --- a/data_structures/arrays/sliding_window_maximum.py +++ b/data_structures/arrays/sliding_window_maximum.py @@ -1,5 +1,4 @@ from collections import deque -from typing import List class SlidingWindowMaximum: @@ -14,7 +13,7 @@ class SlidingWindowMaximum: [3, 3, 5, 5, 6, 7] """ - def max_sliding_window(self, nums: List[int], window_size: int) -> List[int]: + def max_sliding_window(self, nums: list[int], window_size: int) -> list[int]: if not nums: return []