← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/Amazon/Leetcode 276. Paint Fence
CodingOptional
You are designing a decorative pattern for a linear arrangement of n positions. Each position must be assigned one of k available colors. However, there is a strict aesthetic constraint: no more than two consecutive positions can have the same color.
Calculate the total number of distinct valid color patterns that satisfy this constraint.
Example 1:
` Input: n = 3, k = 2 Output: 6 Explanation: Using colors A and B, the valid patterns are:
Example 2:
Input: n = 1, k = 1 Output: 1 Explanation: With one position and one color, there's exactly one way to color it.
Example 3:
` Input: n = 2, k = 3 Output: 9 Explanation: With 2 positions and 3 colors (A, B, C):