Apply Binary State Operations
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 to0and change it to1. If no zero remains, do nothing."Cj": change the state at zero-based indexjto0, 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[]) → StringExamples
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 <= 1051 <= operations.length <= 105- Every operation is either
"L"or"Cj"for an index0 <= j < n.