Tap here to switch tabs
Problem
Submissions

Problem: Find the Count of Monotonic Pairs II

med
30 min
Try to solve the Find the Count of Monotonic Pairs II problem.

Statement

You are given an array of positive integers nums of length n.

A pair of nonnegative integer arrays (arr1, arr2) of length n is called monotonic if for every index i such that 0≤0 \leq i <n< n:

  • arr1[i] + arr2[i] == nums[i]

  • arr1 is monotonically nondecreasing (that is, arr1[i] ≤\leq arr1[i + 1] for all 0≤0 \leq i <n−1< n - 1)

  • arr2 is monotonically nonincreasing (that is, arr2[i] ≥\geq arr2[i + 1] for all 0≤0 \leq i <n−1< n - 1)

Return the total number of valid monotonic pairs. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤2000\leq 2000

  • 1≤1 \leq nums[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Count of Monotonic Pairs II

med
30 min
Try to solve the Find the Count of Monotonic Pairs II problem.

Statement

You are given an array of positive integers nums of length n.

A pair of nonnegative integer arrays (arr1, arr2) of length n is called monotonic if for every index i such that 0≤0 \leq i <n< n:

  • arr1[i] + arr2[i] == nums[i]

  • arr1 is monotonically nondecreasing (that is, arr1[i] ≤\leq arr1[i + 1] for all 0≤0 \leq i <n−1< n - 1)

  • arr2 is monotonically nonincreasing (that is, arr2[i] ≥\geq arr2[i + 1] for all 0≤0 \leq i <n−1< n - 1)

Return the total number of valid monotonic pairs. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤2000\leq 2000

  • 1≤1 \leq nums[i] ≤1000\leq 1000