Maximize Segregation Cost
Updated
Problem statement
An engineer is working to build an integrated binary circuit that takes input a binary string. A binary string consisting of only 0s and 1s can be segregated by moving all the 1s towards the end of the string. For example, the string "01010", after segregation becomes "00011".
In a single operation, any "1" from the binary string can be chosen and moved to the right until it reaches the end of the string or another "1". The cost of the operation is 1 + the number of places the one is moved. For example, in the string "100010", the first one can be moved three places to the right in cost 4. Note that it is mandatory to move a 1 to the maximum possible position to the right.
Given a binary string s, find the maximum number of operations possible to segregate the given string.
Function
maximizeSegregationCost(s: String) → int
Complete the function maximizeSegregationCost in the editor.
maximizeSegregationCost has the following parameter:
String s: a binary string
Returns int: the maximum number of operations possible to segregate the given string
Examples
Example 1
s = "110100"return = 13The final string should be "000111". The optimal way to maximize the number of operations will be:
- Swap the second and the third characters at a cost of 2. The string becomes "101100".
- Swap the first and the second characters at a cost of 2. The string becomes "011100".
- Now, we move each one to the end i.e. moving 2 places at a cost of 3 each.
The total cost of segregation is 2 + 2 + 3 * 3 = 13. Hence the answer is 13.
More Akuna Capital interview questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
Similar questions at other companies
- Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
- Minimize Difference Between Two NumbersMicrosoft · OAMicrosoft interview questions
- Longest Happy String with a Stable Tie RuleAdobe · OAAdobe interview questions
- Return Exact Cash Register ChangeBank of America · OABank of America interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
- Minimum Digit Swaps for the Smallest DifferenceLSEG · OALSEG interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
- Smallest Number With a Given Digit SumAmazon · ONSITE INTERVIEW
- Smallest and Largest Numbers with a Digit ProductJane Street · PHONE SCREENJane Street interview questions
- IP Range to CIDR BlocksAirbnb · PHONE SCREENAirbnb interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)