Tap here to switch tabs
Problem
Submissions

Problem: Find the Count of Monotonic Pairs II

Find the Count of Monotonic Pairs II asks you to count pairs of nonnegative arrays whose corresponding values sum to each input value, with one nondecreasing and the other nonincreasing, modulo a large prime.

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

Find the Count of Monotonic Pairs II asks you to count pairs of nonnegative arrays whose corresponding values sum to each input value, with one nondecreasing and the other nonincreasing, modulo a large prime.

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