Color Fence Posts So Neighbours Differ

Asked at Ripple · Coding Questions · Difficulty: Easy

A fence has `n` posts in a row, and each post is painted in one of `k` colors. Two posts that stand next to each other must not have the same color. Count how many different ways there are to paint the whole fence.

Loading the problem…