Ways to Split Array Into Good Subarrays - LeetCode

PHOTO EMBED

Sun Jun 25 2023 04:23:41 GMT+0000 (Coordinated Universal Time)

Saved by @DxBros #contest #greedy #not_solved #looked_like_dp

int numberOfGoodSubarraySplits(vector<int>& nums) {
    long long ans = 1, m = 1000000007, count  = 0;
    int i = 0;
    while(i < nums.size() && nums[i] == 0) ++i;
    if(i >= nums.size() ) return 0;
    while(i < nums.size()){
        if(nums[i] == 1){  ans = (ans * (count +1 ))%m;  count = 0; }
        else count++;
        i++;
    }
    return ans;
content_copyCOPY

https://leetcode.com/problems/ways-to-split-array-into-good-subarrays/discuss/