We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

longcountArray(intn,intk,intx){// index 0 <= i <= n-1vector<long>a(n);// number of array with length 1 <= i+1 <= n end with xvector<long>b(n);// number of array with length 1 <= i+1 <= n not end with xif(x==1){a[0]=1;b[0]=0;}else{a[0]=0;b[0]=1;}for(inti=1;i<n;i++){b[i]=a[i-1]*(k-1)+b[i-1]*(k-2);b[i]%=1000000007;a[i]=b[i-1];}returna[n-1]%1000000007;}

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

## Construct the Array

You are viewing a single comment's thread. Return to all comments →