Apply Binary State Operations
Updated
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.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
- Count Case-Insensitive Key ChangesOA · Seen Sep 2024
Similar questions at other companies
- Update Pod Counts From LogsSalesforce · OASalesforce interview questions
- Repeated Maximum and Minimum Request ScoreAmazon · OA
- Find Total WeightJP Morgan Chase · OAJP Morgan Chase interview questions
- Insert into a Min-HeapGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms III: Most Booked RoomGoogle · ONSITE INTERVIEWGoogle interview questions
- Dynamic Batch Completion TimesAmbience Healthcare · PHONE SCREEN
- Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
- Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Issue and Reuse 16-Bit TokensMeta · ONSITE INTERVIEWMeta interview questions