← All problemsSign in

3955. Valid Binary Strings With Cost Limit

LeetCodeStringBacktrackingBit ManipulationEnumerationOpen on judge ↗

You are given two integers n and k. The cost of a binary string s is defined as the sum of all indices i (0-based) such that s[i] == '1'. A binary string is considered valid if: - It does not contain two consecutive '1' characters. - Its cost is less than or equal to k. Return a list of all valid binary strings of length n in any order. Example 1: Input: n = 3, k = 1 Output: ["000","010"

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start