Tap here to switch tabs
Problem
Submissions

Problem: Valid Binary Strings With Cost Limit

Try to solve the Valid Binary Strings With Cost Limit problem.

Statement

Given two integers n and k, return a list of all valid binary strings of length n sorted in lexicographical order.

A binary string is considered valid if it satisfies the following conditions:

  • It does not contain two consecutive $ ext{‘1’}$ characters.

  • The total cost of the string is at most k.

The cost of a binary string is defined as the sum of all 00 based indices where the character is $ ext{‘1’}$.

Constraints:

  • 1≤1 \leq n ≤12\leq 12

  • 0≤0 \leq k ≤ext‘n‘⋅(ext‘n‘−1)2\leq \frac{ ext{`n`} \cdot ( ext{`n`} - 1)}{2}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Valid Binary Strings With Cost Limit

Try to solve the Valid Binary Strings With Cost Limit problem.

Statement

Given two integers n and k, return a list of all valid binary strings of length n sorted in lexicographical order.

A binary string is considered valid if it satisfies the following conditions:

  • It does not contain two consecutive $ ext{‘1’}$ characters.

  • The total cost of the string is at most k.

The cost of a binary string is defined as the sum of all 00 based indices where the character is $ ext{‘1’}$.

Constraints:

  • 1≤1 \leq n ≤12\leq 12

  • 0≤0 \leq k ≤ext‘n‘⋅(ext‘n‘−1)2\leq \frac{ ext{`n`} \cdot ( ext{`n`} - 1)}{2}