A data table has n rows, and each row gets one of k background colors. To keep the table readable, no three consecutive rows may share the same color. Two in a row is fine.
Write countRowColorings(n, k) that returns how many different colorings follow this rule, modulo 1000000007.
Input: n = 3, k = 2 Output: 6
All 8 colorings of 3 rows with 2 colors, except the 2 where all rows match.
Input: n = 2, k = 3 Output: 9
Any two colors are fine for two rows: 3 × 3.
1 <= n <= 100001 <= k <= 100000Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #499 Stripe Rows Without Three in a Row. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.