Count Prioritized Binary-Run Operations
Updated
Problem statement
bits consists of zero or more 1s followed by zero or more 0s, and k >= 2. Repeatedly apply the first available rule:
- If at least k zeros exist, remove the last k zeros and prepend one 1.
- Otherwise, if a 1 exists, replace the last 1 with 0.
Stop when neither rule applies and return the number of operations.
Function
countBinaryOperations(bits: String, k: int) → longExamples
Example 1
bits = "10"k = 2return = 3The states by counts are (1,1), (0,2), (1,0), and (0,1).
Example 2
bits = "00"k = 2return = 2Compress two zeros to one 1, then convert that 1 to one zero.
Constraints
1 <= bits.length <= 1000002 <= k <= 100000- The operation count fits in signed 64-bit.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Robot Path That Repeats ForeverOpenAI · OAOpenAI interview questions
- Find Last CharacterGoogle · OAGoogle interview questions
- Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
- Get Max DeletionsJP Morgan Chase · OAJP Morgan Chase interview questions
- FizzBuzzIndeed · OAIndeed interview questions
- FizzBuzzCapital One · OACapital One interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
- Add Decimal Strings ExactlyMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Format a Centered Pagination BarMixpanel · PHONE SCREENMixpanel interview questions