Painting Fence problem
Fatema110 opened this issue · 0 comments
Fatema110 commented
Painting Fence problem
In a fence, with n posts and k available colors, we need to find out how many different
ways we can paint the fence so that at most two adjacent posts have the same color.
Output the answer modulo 10^9 + 7
How many posts are there on the fence? 3
How many colors are available? 7
The number of ways to color the given posts is 336
SAMPLE II
How many posts are there on the fence? 5
How many colors are available? 0
No color is available to paint!!!
Time Complexity: O(n) where 'n' is the number of posts to paint
Space Complexity: O(n)