Skip to main content
Back to problems
Leetcode
Medium
Arrays
Dynamic Programming
Math
Google
Find All Possible Stable Binary Arrays I

Count how many binary arrays can be formed with fixed numbers of 0s and 1s while satisfying a stability condition on consecutive equal values.

Acceptance 0%
Problem Statement

Given two integers representing the number of 0s and 1s available, count how many binary arrays can be formed using exactly those values such that the array remains stable under the problem's constraint on runs of equal elements. Return the total number of valid arrays.

A valid solution should focus on counting arrangements rather than enumerating all possibilities explicitly.

Input Format

  • Two integers describing the available counts of 0s and 1s.
  • An additional integer describing the stability limit or constraint parameter, if applicable to the specific version of the problem.

The exact input format follows the platform's function signature.

Output Format

  • Return the number of stable binary arrays that can be formed.
  • If the answer is large, return it modulo the problem-specified value when required.

Constraints

  • The array must use exactly the given counts of 0s and 1s.
  • The stability condition restricts how consecutive equal values may appear.
  • Time-efficient counting is expected; brute-force generation is not feasible for large counts.
Examples
Sample cases returned by the problem API.

Example 1

Input

zero = 1, one = 1, limit = 1

Output

2

Explanation

The valid arrays are [0,1] and [1,0].

Example 2

Input

zero = 2, one = 1, limit = 2

Output

3

Explanation

The valid arrays are [0,0,1], [0,1,0], and [1,0,0].

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.