Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Operations to Move Ones to the End

med
30 min
Try to solve the Maximum Number of Operations to Move Ones to the End problem.

Statement

You are given a binary string s.

You can perform the following operation on the string any number of times:

Choose an index i such that s[i] is equal to '$1$' and s[i + 1] is equal to '$0$'. Move the character at index i to the right until it reaches either another character '$1$' or the end of the string.

Return the maximum number of operations you can perform.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is either '$0$' or '$1$'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Operations to Move Ones to the End

med
30 min
Try to solve the Maximum Number of Operations to Move Ones to the End problem.

Statement

You are given a binary string s.

You can perform the following operation on the string any number of times:

Choose an index i such that s[i] is equal to '$1$' and s[i + 1] is equal to '$0$'. Move the character at index i to the right until it reaches either another character '$1$' or the end of the string.

Return the maximum number of operations you can perform.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is either '$0$' or '$1$'.