FastPrepTime Needed to Rearrange a Binary String
Problems/Time Needed to Rearrange a Binary String

Time Needed to Rearrange a Binary String

Salesforce logoSalesforce● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Salesforce online assessment. The report names the same binary-string task, only with a different story around it. Our version is about 99% the same as the reported question.

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) → int

Examples

Example 1

s = "0110101"return = 4

The successive strings are 1011010, 1101100, 1110100, and 1111000. After 4 seconds, no 01 remains.

Example 2

s = "11100"return = 0

The string already contains no 01, so the process requires 0 seconds.

Constraints

  • 1 <= s.length <= 1000
  • Every character of s is either 0 or 1.

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

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int secondsToRearrange(String s) {
        // Write your code here.
    }

}
Checking account…