Tap here to switch tabs
Problem
Submissions

Problem: Number of ZigZag Arrays I

Try to solve the Number of ZigZag Arrays I problem.

Statement

You are given three integers n, l, and r.

An array arr of length n is considered a ZigZag array if:

  • l ≤\le arr[i] ≤\le r for every index 0≤i<n0 \le i < n.

  • Adjacent elements strictly alternate between increasing and decreasing throughout the array. That is, one of the following conditions must hold:

    • arr[0] << arr[1] >> arr[2] << arr[3] …\dots

    • arr[0] >> arr[1] << arr[2] >> arr[3] …\dots

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

Constraints:

  • 3≤3 \le n ≤2000\le 2000

  • 1≤1 \le l << r ≤2000\le 2000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of ZigZag Arrays I

Try to solve the Number of ZigZag Arrays I problem.

Statement

You are given three integers n, l, and r.

An array arr of length n is considered a ZigZag array if:

  • l ≤\le arr[i] ≤\le r for every index 0≤i<n0 \le i < n.

  • Adjacent elements strictly alternate between increasing and decreasing throughout the array. That is, one of the following conditions must hold:

    • arr[0] << arr[1] >> arr[2] << arr[3] …\dots

    • arr[0] >> arr[1] << arr[2] >> arr[3] …\dots

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

Constraints:

  • 3≤3 \le n ≤2000\le 2000

  • 1≤1 \le l << r ≤2000\le 2000