Binary Circuit

Problem Overview

  • Compute the maximum total cost to segregate a binary string by moving all 1s to the end under fixed move rules.
  • In each operation, pick a '1' and move it as far right as possible (end or before the next '1'); cost equals 1 plus the number of positions moved.
  • Input: binary string s (length 1–1e5, only '0'/'1'); Output: long integer max cost.
  • Real-world context: organizing bits in an integrated binary circuit.
  • From Akuna interviews; a coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: