3405. Count the Number of Arrays with K Matching Adjacent Elements
Hard
50 Points
Math
Combinatorics
You are given three integers n, m, k. A good array arr of size n is defined as follows:
Return the number of good arrays that can be formed.
Since the answer may be very large, return it modulo 109 + 7.
Examples
Example 1
Input: n = 3, m = 2, k = 1
Output: 4
Explanation:
Example 2
Input: n = 4, m = 2, k = 2
Output: 6
Explanation:
Example 3
Input: n = 5, m = 2, k = 0
Output: 2
Explanation:
Constraints
1 <= n <= 105
1 <= m <= 105
0 <= k <= n - 1
3405. Count the Number of Arrays with K Matching Adjacent Elements
Hard
50 Points
Math
Combinatorics
You are given three integers n, m, k. A good array arr of size n is defined as follows:
Return the number of good arrays that can be formed.
Since the answer may be very large, return it modulo 109 + 7.
Examples
Example 1
Input: n = 3, m = 2, k = 1
Output: 4
Explanation:
Example 2
Input: n = 4, m = 2, k = 2
Output: 6
Explanation:
Example 3
Input: n = 5, m = 2, k = 0
Output: 2
Explanation:
Constraints
1 <= n <= 105
1 <= m <= 105
0 <= k <= n - 1
Count the Number of Arrays with K Matching Adjacent Elements - Practice Coding | SlaveCode