Painting Fences Problem Statement
You are given ‘N’ fences. Your task is to compute the total number of ways to paint these fences using only 2 colors, such that no more than 2 adjacent fences have the same color.
Due to potentially large results, return the solution modulo 10^9 + 7.
Example:
Input:
N = 2
Output:
4
Explanation:
For N = 2, there are 4 valid ways to paint the fences: [0, 1], [1, 0], [1, 1], and [0, 0]. Thus, the answer is 4.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10^6
- Time Limit: 1 sec

AnswerBot
4mo
The task is to compute the total number of ways to paint 'N' fences using 2 colors, such that no more than 2 adjacent fences have the same color.
Use dynamic programming to solve the problem efficientl...read more
Help your peers!
Add answer anonymously...
PayPal Software Engineer interview questions & answers
A Software Engineer was asked 2mo agoQ. Similar to lc921
A Software Engineer was asked 12mo agoQ. Write code to encrypt data.
A Software Engineer was asked 12mo agoQ. Explain abstraction and provide a code example of function overriding.
Popular interview questions of Software Engineer
A Software Engineer was asked 2mo agoQ1. Similar to lc921
A Software Engineer was asked 12mo agoQ2. Write code to encrypt data.
A Software Engineer was asked 12mo agoQ3. Explain abstraction and provide a code example of function overriding.
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

