FastPrepApply Binary State Operations

Apply Binary State Operations

Visa logoVisa● EasyFULLTIMEOA
Learn

Problem statement

You have a binary state array of length n, initially filled with 0. Apply the strings in operations in order:

  • "L": find the leftmost state equal to 0 and change it to 1. If no zero remains, do nothing.
  • "Cj": change the state at zero-based index j to 0, regardless of its current value. The index may contain multiple digits.

Return the final state as a string of 0 and 1 characters.

Function

applyBinaryStateOperations(n: int, operations: String[]) → String

Examples

Example 1

n = 8operations = ["L","L","C1","C6","L"]return = "11000000"

The first two operations set indices 0 and 1. C1 clears index 1, C6 leaves an existing zero unchanged, and the final L sets index 1 again.

Example 2

n = 4operations = ["L","L","L","C0","L"]return = "1110"

Three loads produce 1110. Clearing index 0 produces 0110, and the last load selects index 0 again.

Constraints

  • 1 <= n <= 105
  • 1 <= operations.length <= 105
  • Every operation is either "L" or "Cj" for an index 0 <= j < n.

More Visa problems

See Visa hiring insights
public String applyBinaryStateOperations(int n, String[] operations) {
    // Write your code here.
}
n8
operations["L","L","C1","C6","L"]
expected"11000000"
Checking account…