allcoding1
27.6K subscribers
2.2K photos
2 videos
77 files
853 links
Download Telegram
def count_arrays(N, K, X):
    MOD = 1000000007
   
    if N == 1:
        return 1 if X == 1 else 0

    a = [0] * (N + 1)
    b = [0] * (N + 1)
   
    a[1] = 1
    b[1] = 0
   
    for i in range(2, N + 1):
        a[i] = (a[i - 1] * (K - 2) + b[i - 1] * (K - 1)) % MOD
        b[i] = a[i - 1] % MOD
   
    return b[N]


N = int(input())
K = int(input())
X = int(input())
print(count_arrays(N, K, X))


Number Of Array code

Thoughtwork exam
Python3

Telegram:- @allcoding1
👍5👎2🔥1
Thoughtwork exam
Python3

Telegram:- @allcoding1
👍3
Dark lane

Thoughtwork exam
Python3

Telegram:- @allcoding1
Well growing crops

Thoughtwork exam
Python3

Telegram:- @allcoding1
Prime partition

Thoughtwork exam
Python3

Telegram:- @allcoding1
👍1
Dark lane

Thoughtwork exam
Python3

Telegram:- @allcoding1
👍1
Count children

Thoughtwork exam
Python3

Telegram:- @allcoding1
👍5
👍3
Accenture

Pseudo code
👍1🔥1