โ† Paytm questions

Painting Fence Algorithm

Filed under Paytm

Given a fence with n posts and k colors, find the total number of ways to paint the fence such that no more than two adjacent fence posts have the same color. Return the result modulo 10^9 + 7.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Paytm questions

Collected from public candidate posts and coding forums. Updated Nov 2026.