0 out of 464 challenges solved
You are tasked with writing a function to calculate the number of ways to paint a fence with `n` posts using `k` colors such that no more than two adjacent posts have the same color. The result should be returned modulo $10^9+7$. #### Example Usage ```python [main.nopy] count_no_of_ways(2, 4) # Output: 16 count_no_of_ways(3, 2) # Output: 6 count_no_of_ways(4, 4) # Output: 228 ``` #### Constraints - `1 <= n <= 10^5` - `1 <= k <= 10^3`
def count_no_of_ways(n, k): """ Calculate the number of ways to paint a fence with n posts and k colors such that no more than two adjacent posts have the same color. Args: n (int): The number of posts. k (int): The number of colors. Returns: int: The number of ways to paint the fence modulo 10^9+7. """ # Placeholder for the solution pass