Tap here to switch tabs
Problem
Submissions

Problem: Minimum Suffix Flips

med
30 min
Try to solve the Minimum Suffix Flips problem.

Statement

You are given a 00 indexed binary string target of length n.

You have another binary string s of length n, where all characters are initially '0'. You want to make s equal to target.

In one operation, you can choose an index i such that 0≤i<n0 \leq i < n and flip all the characters in s from index i to index n−1n - 1 inclusive. Flipping changes '0' to '1' and '1' to '0'.

Return the minimum number of operations needed to make s equal to target.

Constraints:

  • n == target.length

  • 1≤1 \leq n ≤105\leq 10^5

  • target[i] is either '0' or '1'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Suffix Flips

med
30 min
Try to solve the Minimum Suffix Flips problem.

Statement

You are given a 00 indexed binary string target of length n.

You have another binary string s of length n, where all characters are initially '0'. You want to make s equal to target.

In one operation, you can choose an index i such that 0≤i<n0 \leq i < n and flip all the characters in s from index i to index n−1n - 1 inclusive. Flipping changes '0' to '1' and '1' to '0'.

Return the minimum number of operations needed to make s equal to target.

Constraints:

  • n == target.length

  • 1≤1 \leq n ≤105\leq 10^5

  • target[i] is either '0' or '1'.