FastPrepMaximum Redundancy After One Segment Flip
Problems/Maximum Redundancy After One Segment Flip

Maximum Redundancy After One Segment Flip

Bloomberg LP logoBloomberg LP● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was the first of three coding tasks in a Bloomberg online assessment for 2027 full-time roles. The post asks how many different totals of working machines a single flip of one stretch of a 0/1 row can produce, and it gives two sample answers.

Those two samples cannot both hold under one rule. Here, leaving the row unchanged also counts as a choice, since that is the only way the all-zero sample (0000 gives 5) works. Under this rule the other sample (0011) gives 5, not the 4 the post lists. The post also asks for a maximum without saying what to maximize, so here the answer counts the different totals. The post gives no limits, so the length limit of 10^5 is our choice.

Our version is about 75% the same as the reported question.

You are given a string servers. Character i is '1' if server i is up and '0' if it is down.

You may do one flip. Pick a block of servers that sit next to each other and switch every server in it: a '0' becomes '1' and a '1' becomes '0'. You may also pick an empty block, which leaves every server as it is.

Each choice of block ends with some number of up servers. The redundancy is how many different up-server counts you can end with over all choices.

Return the redundancy.

Function

maxRedundancy(servers: String) → int

Examples

Example 1

servers = "0000"return = 5

All four servers are down, so leaving them alone gives 0 up servers. Flipping a block of 1, 2, 3 or 4 servers turns that many servers on, giving 1, 2, 3 or 4 up servers.

The reachable counts are 0, 1, 2, 3 and 4, so the answer is 5.

Example 2

servers = "0011"return = 5

Leaving the servers alone gives 2 up servers. Flipping "00" gives "1111" with 4 up. Flipping only the first server gives "1011" with 3 up. Flipping only the last server gives "0010" with 1 up. Flipping "11" gives "0000" with 0 up.

The reachable counts are 0, 1, 2, 3 and 4, so the answer is 5.

Example 3

servers = "111"return = 4

All three servers are up. Leaving them alone gives 3. Flipping a block of 1, 2 or 3 servers turns that many off, giving 2, 1 or 0.

The reachable counts are 0, 1, 2 and 3, so the answer is 4.

Example 4

servers = "10110"return = 4

There are 3 up servers to start. Flipping just the server at index 1 or index 4 gives 4 up servers, and no block does better, because any block holding both down servers also holds two up servers.

Flipping "11" at indices 2 and 3 gives "10000" with 1 up server. No block reaches 0, because any block holding all three up servers also holds the down server at index 1.

So the reachable counts are 1, 2, 3 and 4, and the answer is 4.

Constraints

  • 1 <= servers.length <= 10^5
  • Each character of servers is '0' or '1'.

More Bloomberg LP interview questions

  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Longest Distance in a Frequency-Limited NetworkOA · Seen Sep 2026
  • Sum of Pipeline Response TimesOA · Seen Sep 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Design an Ordered StreamOA · PHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Count Teams Outscoring a Target TeamOA · Seen Feb 2023
  • Ashley Loves Numbers (Financial Engineer)OA · Seen Nov 2019
  • Consecutive Sum (Financial Engineer Intern)OA · Seen Nov 2019
  • Find Longest ChainOA · Seen Sep 2017
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Maximum Positive FeedbackTikTok · OATikTok interview questions
  • Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
  • Longest Subsequence That Is a SubstringBooking.com · OA
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
  • Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
  • Maximum Equalized Substrings After One Adjacent SwapVisa · OAVisa interview questions
  • Minimum-Cost Digit String DecodingSquadStack.ai · OA
  • Balanced Split String with WildcardsTwo Sigma · OATwo Sigma interview questions

Bloomberg LP interview experiences

  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg SWE Phone Screens with Two Teams: 1 Experience
  • Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
  • Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
  • Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
  • Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int maxRedundancy(String servers) {
        // Write your code here.
    }
}
Checking account…