Reported May 2026
IDFCrecursion

Special Binary String

Reported by candidates from IDFC's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live IDFC OA. Under 2s to a working solution.
Founder's read

The constraint that kills brute force here is simple: you can swap any two adjacent special substrings any number of times, so the reachable strings explode fast. IDFC reported this one in May 2026, and it's LeetCode's Special Binary String in disguise. Trying every swap sequence won't survive past a tiny input. The real answer is a recursive decomposition plus a sort. If you know the shape, it's maybe 15 lines. If you blank on the idea, StealthCoder runs invisibly during the live OA and can hand you the approach so you aren't staring at a blank editor.

The problem

A special binary string is a binary string with both of the following properties:
The number of '0' characters is equal to the number of '1' characters.
Every prefix of the string has at least as many '1' characters as '0' characters.
You are given a special binary string s.
In one move, choose two consecutive non-empty special substrings of s and swap them. Two substrings are consecutive if the last character of the first substring is immediately before the first character of the second substring.
Return the lexicographically largest string possible after applying any number of these moves.

Function
makeLargestSpecial(s: String) → String

Examples
Example 1
s = "11011000"
return = "11100100"
The two consecutive special substrings "10" and "1100" inside "11011000" can be swapped to produce "11100100".
Example 2
s = "10"
return = "10"
The string is already the only possible special binary string with these characters.

Constraints
s is a special binary string.
s contains only '0' and '1'.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Think of 1 as an open paren and 0 as a close paren. A special string is a balanced parentheses string. Split s into top-level primitive pieces by tracking a running balance, and cut each time it hits zero. For each piece, strip the outer 1 and 0, recurse on the inside, then wrap it back as 1 + inner + 0. Collect the processed pieces, sort them in descending lexicographic order, and join them. Sorting descending is what gives the largest string, since swaps of adjacent specials let you reorder pieces freely. The common pitfall is forgetting to recurse before sorting, which leaves inner pieces unoptimized. Another is sorting ascending by habit. Complexity is roughly O(n^2) worst case from string building and sorting at each depth. StealthCoder is your hedge if the balanced-paren mapping doesn't click under pressure in the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Special Binary String cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as special binary string. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass IDFC's OA.

IDFC reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Special Binary String FAQ

What's the trick to Special Binary String?+

Treat 1 as an open bracket and 0 as a close bracket. Split into primitive balanced pieces, recursively maximize each piece's inside, then sort the pieces in descending order and concatenate. That sort is the whole payoff.

How hard is this really for the IDFC OA?+

It's labeled hard on LeetCode, but the solution is short once you see the parentheses mapping. The difficulty is the insight, not the code. If you've seen balanced bracket splitting before, it takes about 10 minutes.

Why does sorting descending give the largest string?+

Swapping adjacent special substrings lets you arrange top-level pieces in any order. To get the lexicographically largest result, you put the largest piece first, which is a descending sort. Each piece is already maximized internally by recursion.

What's the most common bug?+

Forgetting to wrap the recursed inner part back with 1 and 0, or skipping recursion entirely. Another is cutting pieces at the wrong spot. Cut exactly when the running balance returns to zero, not before.

How do I prepare for this in 48 hours?+

Write the solution from scratch twice. Practice the balance counter split, the recursion on s[i+1:j], and the reverse sort. Then trace Example 1 by hand. Also skim related balanced parentheses problems to make the mapping feel automatic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with IDFC.

OA at IDFC?
Invisible during screen share
Get it