FastPrepBinary Sorting Rounds After Flips
Problems/Binary Sorting Rounds After Flips

Binary Sorting Rounds After Flips

Visa logoVisa● HardINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the sorting-round metric and zero-to-one update effect but omits the callable batch interface, index convention, and bounds. The judged core task matches the report at about 90%.

You are given a binary string binary and an array flips. Process the flip indices in order. Each flip changes the character at that index from 0 to 1.

After every flip, define the current sorting-round count as the maximum, over all remaining 0 characters, of the number of 1 characters before that zero. If no zero remains, the sorting-round count is 0.

Return the sorting-round count after each flip.

Function

getSortingRounds(binary: String, flips: int[]) → int[]

Examples

Example 1

binary = "10100"flips = [1,3]return = [3,4]

After flipping index 1, the remaining zeros are at indices 3 and 4, each with three ones before it. After flipping index 3, the final zero has four ones before it.

Example 2

binary = "000"flips = [1,0,2]return = [1,2,0]

The first flip leaves the last zero with one preceding one. The second leaves it with two preceding ones. The final flip removes the last zero, so the answer becomes 0.

Constraints

  • 1 <= binary.length <= 2 * 10^5.
  • binary contains only 0 and 1.
  • 1 <= flips.length <= binary.length.
  • Every value in flips is a distinct 0-based index whose current character is 0.

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int[] getSortingRounds(String binary, int[] flips) {
      // write your code here
    }
}
Checking account…