Time Needed to Rearrange a Binary String
Updated
Problem statement
You are given a binary string s. During each second, replace every occurrence of 01 with 10 simultaneously.
Repeat the process until s contains no occurrence of 01. Return the number of seconds required.
Function
secondsToRearrange(s: String) → intExamples
Example 1
s = "0110101"return = 4The successive strings are 1011010, 1101100, 1110100, and 1111000. After 4 seconds, no 01 remains.
Example 2
s = "11100"return = 0The string already contains no 01, so the process requires 0 seconds.
Constraints
1 <= s.length <= 1000- Every character of
sis either0or1.
More Salesforce Online Assessment questions
- Count Subarrays With Product Equal to KOA · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
- Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
- Run-Length String CompressionOA · Seen Sep 2026
- Maximum Requests in WindowOA · Seen Sep 2026
- Final Pod Counts After LogsOA · Seen Aug 2026
- Minimum Removals to Balance ArrayOA · Seen Aug 2026
- Is This Date a Weekend?OA · Seen Aug 2026
- Maximum Barbell WeightOA · Seen Jul 2026
Similar questions at other companies
- Binary String Swap TimeMicrosoft · OAMicrosoft interview questions
- Reliable LLM Call with Independent Retry BudgetsStripe · OAStripe interview questions
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Tennis Game ScoreAbridge · OAAbridge interview questions
- Longest Subsequence That Is a SubstringBooking.com · OA
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Parcel Event TrackingAirbnb · OAAirbnb interview questions
- Repair One Movement InstructionOpenAI · OAOpenAI interview questions