Skip to content

Commit c989493

Browse files
committed
Jun 17
1 parent 0e04873 commit c989493

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from math import comb
2+
3+
4+
class Solution:
5+
MOD = 10**9 + 7
6+
7+
def countGoodArrays(self, n: int, m: int, k: int) -> int:
8+
return (comb(n - 1, k) * m * pow(m - 1, n - k - 1, self.MOD)) % self.MOD
9+
10+
11+
def main():
12+
n = 3
13+
m = 2
14+
k = 1
15+
assert Solution().countGoodArrays(n, m, k) == 4
16+
17+
n = 4
18+
m = 2
19+
k = 2
20+
assert Solution().countGoodArrays(n, m, k) == 6
21+
22+
23+
if __name__ == '__main__':
24+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| June 14 | []() | | |
2121
| June 15 | []() | | |
2222
| June 16 | [2016. Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements/) | Easy | Solved |
23-
| June 17 | []() | | |
23+
| June 17 | [3405. Count the Number of Arrays with K Matching Adjacent Elements](https://leetcode.com/problems/count-the-number-of-arrays-with-k-matching-adjacent-elements/) | Hard | Unsolved |
2424
| June 18 | []() | | |
2525
| June 19 | []() | | |
2626
| June 20 | []() | | |
@@ -41,4 +41,4 @@
4141
| --- | --- | --- | --- |
4242
| Easy | 3 | 3 | 0 |
4343
| Medium | 7 | 4 | 3 |
44-
| Hard | 4 | 2 | 2 |
44+
| Hard | 5 | 2 | 3 |

0 commit comments

Comments
 (0)