Ctrl K

Zeros Left, Ones Right

Easy
You are given a string bits made of 0 and 1. Cut it in one place into two non-empty parts, a left one and a right one. The cut scores the number of zeros in the left part plus the number of ones in the right part. Return the highest score you can get.
Example 1
bits='010011' → 5

Cut after "0100": three zeros on the left and two ones on the right, 5 in total. Nothing scores higher.

Example 2
bits='000' → 2

There are no ones, and the right part cannot be empty, so the left part holds at most two zeros.

Example 3
bits='10' → 0
Constraints
  • 2 ≤ len(bits) ≤ 500
  • bits contains only the characters 0 and 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRoll Letters by Prefix MediumUp and Down Orderings HardPalindrome After a Few Fixes MediumMatching Stretch Within Budget MediumEven Vowel Stretch Medium
loading Python…
Input
bits='010011'
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 146 tests on the server, hidden ones included.