• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
December 15, 2023 |1.5K Views
PROBLEM OF THE DAY : 14/12/2023 | Painting the Fence
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of DP but also build up problem-solving skills.

In this problem, Given a fence with n posts and k colors, find out the number of ways of painting the fence so that not more than two consecutive posts have the same colors. Since the answer can be large return it modulo 10^9 + 7.

Example :

Input:
n = 3
k = 2 
Output: 6

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/painting-the-fence3727/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/5431ecf7-651c-47a5-bd61-99c82cb3f52f