Find All Possible Stable Binary Arrays II
Real-world version: Steady Punch Card LayoutsThe statement here is our own: the same inputs, outputs and technique.
A punch card is a single row of cells. Every cell is either a blank or a mark. A card is steady when all three hold:
- it carries exactly
zeroblanks; - it carries exactly
onemarks; - no run of
limit + 1cells in a row is all blanks or all marks.
Two cards are different when some position carries a different kind of cell. Return how many steady cards exist, taken modulo 1000000007.
Examples
Example 1
- Input
- zero = 1, one = 2, limit = 1
- Output
- 1
With a cap of one, no two neighbouring cells may match. Only the card reading mark, blank, mark satisfies that while carrying one blank and two marks.
Example 2
- Input
- zero = 2, one = 2, limit = 1
- Output
- 2
A cap of one forces the kinds to alternate, so the card either opens with a blank or opens with a mark, giving two steady cards.
Example 3
- Input
- zero = 3, one = 3, limit = 2
- Output
- 14
Cards such as blank, blank, mark, blank, mark, mark are steady, since no three cells in a row match. Counting every such card gives this many.
Constraints
- 1 <= zero <= 1000
- 1 <= one <= 1000
- 1 <= limit <= 1000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def steady_layouts(zero: int, one: int, limit: int) -> int:public int steadyLayouts(int zero, int one, int limit)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Stone Game IIReal-world version: Front Loaded Tray HaulMedium
- Jump Game VIIReal-world version: Pontoon Crossing With A Hop RangeMedium
- Find All Possible Stable Binary Arrays IReal-world version: Settled Control TapesMedium
- Maximum Frequency After Subarray OperationReal-world version: Most Dials Reading k After One NudgeMedium