Problem · String
Reverse Binary String with Minimum Shifts
Learn this problemProblem statement
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
reverseBinaryString(s: String) → int
Complete the function reverseBinaryString in the editor.
reverseBinaryString has the following parameter:
String s: a binary string
Returns
int: the minimum number of operations required to reverse the binary string
Examples
Example 1
s = "00110101"return = 3Here 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
1 ≤ S.length ≤ 1e5
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026