Apply Binary State Operations
Problem statement
For this exercise, assume the initial binary state is supplied as a string state. Apply the strings in operations from left to right:
"L": find the smallest index whose current value is0and change it to1. If no zero remains, do nothing."Cj": change the value at zero-based indexjto0, regardless of its current value. The index may contain more than one digit.
Return the final binary state as a string.
Function
applyBinaryStateOperations(state: String, operations: String[]) → StringExamples
Example 1
state = "00100"operations = ["L","C2","L"]return = "11000"The first load sets index 0, producing 10100. Clearing index 2 produces 10000. The final load sets the new leftmost zero at index 1.
Example 2
state = "111"operations = ["L","C1","L"]return = "111"The first load has no zero to change. Clearing index 1 creates the state 101, and the final load sets that position back to 1.
Constraints
1 <= state.length <= 100000statecontains only0and1.1 <= operations.length <= 100000- Every operation is either
"L"or"Cj"for a valid index0 <= j < state.length.