Skip to content

Commit

Permalink
Jan 3
Browse files Browse the repository at this point in the history
  • Loading branch information
siddydutta committed Jan 3, 2025
1 parent 8d2a602 commit 1b4208a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions 2025-01-January-LeetCoding-Challenge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | []() | | |
Expand Down Expand Up @@ -40,5 +40,5 @@
| Level | Problems | Solved | Unsolved |
| --- | --- | --- | --- |
| Easy | 1 | 1 | 0 |
| Medium | 1 | 1 | 0 |
| Medium | 2 | 2 | 0 |
| Hard | 0 | 0 | 0 |

0 comments on commit 1b4208a

Please sign in to comment.