Problem · String

Find Minimum Operations (It seems for FT in US but intern in CN)

Learn this problem
HardAmazonNEW GRADINTERNOA
See Amazon hiring insights

Problem statement

Amazon Web Services (AWS) manages grayscale images using sequences of black and white pixels. Each image is represented as a binary string where '1' indicates a white pixel, and '0' represents a black pixel. The reverse of an image is simply the binary string in reverse order. For example, reversing "11010" results in "01011."

To maintain backups, AWS plans to generate the reverse of each image. You can perform a specific operation any number of times to achieve this: select any character from the string, remove it, and append it to the end. This operation mimics shifting a pixel to the back of the string.

Your goal is to determine the minimum number of operations required to convert the original binary representation of the image into its reversed version.

Function

findMinimumOperations(pixelString: String) → int

Examples

Example 1

pixelString = "0100110"return = 3
Example 1 illustration

Example 2

pixelString = "00110101"return = 3
The string can be reversed in minimum 3 moves using the following sequence: 1. 00110101 -> 00101011 2. 00101011 -> 01010110 3. 01010110 -> 10101100

Example 3

pixelString = "101011"return = 2
The explanation is incomplete, so I did not include it.

Constraints

1 <= pixelString.length() <= 10^5

More Amazon problems

drafts saved locally
public int findMinimumOperations(String pixelString) {
  // write your code here
}
pixelString"0100110"
expected3
checking account