#3700
Number of ZigZag Arrays II
expert · 1250 · lc hard +32 · 57.5% accepted · 28 likes · top 53%
Description
Given integers n, l, and r, count all length-n arrays with elements in [l, r] where no two adjacent elements are equal and no three consecutive elements are strictly increasing or strictly decreasing; return the result modulo 109 + 7.
Code
1
2
3