Search
⌘K

Leetcode 276. Paint Fence

Count the number of ways to paint n fence posts with k colors such that no more than two adjacent posts have the same color. This is a dynamic programming problem where you derive a recurrence by tracking configurations that end with the same color as the previous post versus a different color.

Asked at:

Amazon

Amazon


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Early February, 2025

Amazon

Amazon

Mid-level

Comments

Your account is free and you can post anonymously if you choose.