A performance dashboard has n heavy widgets in a row, and each one is either on (1) or off (0). Two neighboring heavy widgets may never both be on, or the page stutters.
Write countSafeRows(n) that returns how many on/off patterns of length n follow this rule, modulo 1000000007.
Input: n = 3 Output: 5
000, 001, 010, 100, and 101.
Input: n = 1 Output: 2
0 or 1.
1 <= n <= 1000000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #565 Flag Rows Without Two Heavy Neighbors. 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.