Tap here to switch tabs
Problem
Submissions

Problem: Choose Numbers From Two Arrays in Range

med
30 min
Try to solve the Choose Numbers From Two Arrays in Range problem.

Statement

You are given two 00 indexed integer arrays nums1 and nums2 of length n.

A range [l,r][l, r] with 0≤l≤r<n0 \leq l \leq r < n is considered balanced if, for every index ii in the range, you choose exactly one element from either nums1[i] or nums2[i] such that the sum of the elements chosen from nums1 is equal to the sum of the elements chosen from nums2.

Return the total number of balanced ranges. Two ranges are considered different if their boundary indices [l,r][l, r] differ or if a different choice is made at any index within the range. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • n ==== nums1.length ==== nums2.length

  • 1≤1 \leq n ≤100\leq 100

  • 0≤0 \leq nums1[i], nums2[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Choose Numbers From Two Arrays in Range

med
30 min
Try to solve the Choose Numbers From Two Arrays in Range problem.

Statement

You are given two 00 indexed integer arrays nums1 and nums2 of length n.

A range [l,r][l, r] with 0≤l≤r<n0 \leq l \leq r < n is considered balanced if, for every index ii in the range, you choose exactly one element from either nums1[i] or nums2[i] such that the sum of the elements chosen from nums1 is equal to the sum of the elements chosen from nums2.

Return the total number of balanced ranges. Two ranges are considered different if their boundary indices [l,r][l, r] differ or if a different choice is made at any index within the range. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • n ==== nums1.length ==== nums2.length

  • 1≤1 \leq n ≤100\leq 100

  • 0≤0 \leq nums1[i], nums2[i] ≤100\leq 100