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
Be the first one to answer
Add answer anonymously...
PayPal Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter