Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
490 B
1
Indexable
Never
class Solution
{
    long countWays(int n,int k)
    {
        //code here.
        if(n == 0 ) return 0; // in case of no wall
        // this reprsent if we have only one wall
        long total = k,same = 0 , diff = k , mod = (long) 1e9 + 7;
        
        for(int i = 2 ; i<= n;i++)
        {
            same = diff;
            diff = ((k-1)%mod*(total%mod));
            
            total = (same%mod + diff%mod)%mod;
        }
        
        return total;
        
    
    }
}
Leave a Comment