diff --git a/2025-01-January-LeetCoding-Challenge/Number of Ways to Split Array.py b/2025-01-January-LeetCoding-Challenge/Number of Ways to Split Array.py new file mode 100644 index 0000000..96b776b --- /dev/null +++ b/2025-01-January-LeetCoding-Challenge/Number of Ways to Split Array.py @@ -0,0 +1,24 @@ +from typing import List + + +class Solution: + def waysToSplitArray(self, nums: List[int]) -> int: + prefix_sum, total_sum = 0, sum(nums) + valid_splits = 0 + for num in nums[:-1]: + prefix_sum += num + if prefix_sum >= total_sum - prefix_sum: + valid_splits += 1 + return valid_splits + + +def main(): + nums = [10, 4, -8, 7] + assert Solution().waysToSplitArray(nums) == 2 + + nums = [2, 3, 1, 0] + assert Solution().waysToSplitArray(nums) == 2 + + +if __name__ == '__main__': + main() diff --git a/2025-01-January-LeetCoding-Challenge/README.md b/2025-01-January-LeetCoding-Challenge/README.md index ab8bb61..295e68d 100644 --- a/2025-01-January-LeetCoding-Challenge/README.md +++ b/2025-01-January-LeetCoding-Challenge/README.md @@ -5,7 +5,7 @@ | --- | --- | --- | --- | | January 1 | [1422. Maximum Score After Splitting a String](https://leetcode.com/problems/maximum-score-after-splitting-a-string/) | Easy | Solved | | January 2 | [2559. Count Vowel Strings in Ranges](https://leetcode.com/problems/count-vowel-strings-in-ranges/) | Medium | Solved | -| January 3 | []() | | | +| January 3 | [2270. Number of Ways to Split Array](https://leetcode.com/problems/number-of-ways-to-split-array/) | Medium | Solved | | January 4 | []() | | | | January 5 | []() | | | | January 6 | []() | | | @@ -40,5 +40,5 @@ | Level | Problems | Solved | Unsolved | | --- | --- | --- | --- | | Easy | 1 | 1 | 0 | -| Medium | 1 | 1 | 0 | +| Medium | 2 | 2 | 0 | | Hard | 0 | 0 | 0 |