All problems
1112EasyStringPrefix Sum

Cutting the Strip for the Best Score

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1422Maximum Score After Splitting a String

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A strip marks holds only the characters 0 and 1. Cut it once into a left piece and a right piece, and neither piece may be empty.

A cut scores the number of 0 characters in the left piece plus the number of 1 characters in the right piece.

Return the highest score a cut can reach.

Examples

Example 1

Input
marks = "0011"
Output
4

Cutting after the two zeros puts both of them on the left and both ones on the right, scoring 2 plus 2.

Example 2

Input
marks = "10"
Output
0

Only one cut is possible. The left piece is a single 1 and the right piece a single 0, so neither side scores anything.

Example 3

Input
marks = "0000011111"
Output
10

Cutting where the zeros run out puts all five zeros on the left and all five ones on the right.

Constraints

  • 2 <= marks.length <= 500
  • marks holds only the characters 0 and 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def max_score(marks: str) -> int:
Java
public int maxScore(String marks)
September 7
Apply