Zepruv › Coding problems

Ways to Split Array Into Three Subarrays

Medium · Array, Two Pointers, Binary Search, Prefix Sum

A split of an integer array is good if:
Given nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 109 + 7.

Example 1

Input: nums = [1,1,1]
Output: 1

The only good way to split nums is [1] [1] [1].

Example 2

Input: nums = [1,2,2,2,5,0]
Output: 3

There are three good ways of splitting nums: [1] [2] [2,2,5,0] [1] [2,2] [2,5,0] [1,2] [2,2] [5,0]

Example 3

Input: nums = [3,2,1]
Output: 0

There is no good way to split nums.

Constraints

Starter code (python)

class Solution(object):
    def waysToSplit(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        

Related problems

Previous: Count Good Meals · Next: Minimum Operations to Make a Subsequence · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.