Question: 
Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors.


Model's Code:
def count_no_of_ways(n, k):
    if n == 0:
        return 0
    if n == 1:
        return k
    if n == 2:
        return k * k

    same = k  # Ways to paint last 2 posts the same color
    diff = k * (k - 1)  # Ways to paint last 2 posts different colors
    total = same + diff

    for i in range(3, n + 1):
        new_same = diff
        new_diff = (total * (k - 1)) % (10**9 + 7)
        total = (new_same + new_diff) % (10**9 + 7)
        same, diff = new_same, new_diff

    return total



Sample Correct Code:
def count_no_of_ways(n, k): 
	dp = [0] * (n + 1) 
	total = k 
	mod = 1000000007
	dp[1] = k 
	dp[2] = k * k	 
	for i in range(3,n+1): 
		dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod 
	return dp[n]


Asserts:
assert count_no_of_ways(2, 4) == 16
assert count_no_of_ways(3, 2) == 6
assert count_no_of_ways(4, 4) == 228


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: PASS

Test 291 of 974: 210/291 (72.16494845360825%): success