← All questions
HardCoding
Special Binary String
Asked atTSTechMojo Solutions
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Track balance, adding one for 1 and subtracting one for 0.
- 02Split whenever balance returns to zero.
- 03Recursively maximize the interior of each primitive block.
- 04Sort complete blocks descending and concatenate them.
Reference answer
Then expect these follow-ups
Why does descending block order maximize the result?
Tests: greedy proof
How can you reduce substring copying?
Tests: implementation
Hiring now
Backend engineer roles are open right now
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.

Founding Engineer (AI + Backend) - Remote, India
Openbenchmarks · Remote

Software Engineer I, Backend (Continuous Delivery)
Affirm · Remote Canada

Senior Software Engineer – Python Backend & Manufacturing Systems
Diamond Foundry · Bay Area, California
Next question