FastPrepFastPrep
Problem Brief

Reverse Binary String with Minimum Shifts

NEW GRADOA
See Amazon online assessment and hiring insights

You are given a binary string. Find the minimum number of operations required to reverse it. An operation is defined as: Remove a character from any index and append it to the end of the string.

Function Description

Complete the function reverseBinaryString in the editor.

reverseBinaryString has the following parameter:

  1. String s: a binary string

Returns

int: the minimum number of operations required to reverse the binary string

1Example 1

Input
s = "00110101"
Output
3
Explanation
Here is one way to reverse the string in 3 operations:
  • 00110101 - 00101011 (index 3 was appended at the end)
  • 00101011 - 01010110 (index 0 was appended at the end)
  • 01010110 - 10101100 (index 0 was appended at the end)
  • So the answer here is 3 operations.

    Constraints

    Limits and guarantees your solution can rely on.

    1 ≤ S.length ≤ 1e5

    public int reverseBinaryString(String s) {
      // write your code here
    }
    
    Input

    s

    "00110101"

    Output

    3

    Sign in to submit your solution.