Apply Binary State Operations
Updated
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.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Lift Total TravelInfosys · OAInfosys interview questions
- Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
- Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
- Recursively Expanded Shell Command CountsHudson River Trading · OAHudson River Trading interview questions