Skip to content

Commit 86a4cc3

Browse files
committed
add 004. Construct the Array
1 parent d250ce0 commit 86a4cc3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Problem: https://www.hackerrank.com/challenges/construct-the-array/problem
2+
# Score: 35
3+
4+
5+
def count_array(n, k, x):
6+
dp = [[1], [1]]
7+
if x == 1:
8+
dp = [[1], [0]]
9+
else:
10+
dp = [[1], [1]]
11+
12+
for x in range(n - 2):
13+
dp[0].append(dp[0][-1] * (k - 1) % (10 ** 9 + 7))
14+
dp[1].append((dp[0][-1] - dp[1][-1]) % (10 ** 9 + 7))
15+
return dp[1][-1]
16+
17+
18+
n, k, x = map(int, input().split())
19+
print(count_array(n, k, x))

0 commit comments

Comments
 (0)