FastPrepCount Prioritized Binary-Run Operations
Problems/Count Prioritized Binary-Run Operations

Count Prioritized Binary-Run Operations

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report describes an input of runs of 1s and 0s, prioritized compression of k zeros, last-one conversion, an end condition, and an operation count. Our version sets k to at least two so the reported rewrite rules always end, and gives the function a string input.

bits consists of zero or more 1s followed by zero or more 0s, and k >= 2. Repeatedly apply the first available rule:

  1. If at least k zeros exist, remove the last k zeros and prepend one 1.
  2. 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) → long

Examples

Example 1

bits = "10"k = 2return = 3

The states by counts are (1,1), (0,2), (1,0), and (0,1).

Example 2

bits = "00"k = 2return = 2

Compress two zeros to one 1, then convert that 1 to one zero.

Constraints

  • 1 <= bits.length <= 100000
  • 2 <= 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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public long countBinaryOperations(String bits, int k) {
        // Write your code here.
    }

}
Checking account…