Reported October 2026
Pineconestring

Minimum Binary String Length After Pair Removals

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

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

Pinecone reported this one in October 2026, and the 100000 length cap is the first thing to read. Simulating removals one at a time, rescanning the string after each, is O(n^2) and dies on a long input. The problem looks like a stack exercise on a binary string, but there's a shortcut that makes it a few lines. If you blank during the OA, StealthCoder runs invisibly as a safety net and surfaces the answer. Know the trick first and you won't need it.

The problem

Given a binary string s, you may repeatedly remove any adjacent pair equal to 01 or 10.
Return the minimum possible length of the remaining string.

Function
minimumRemainingLength(s: String) → int

Examples
Example 1
s = "0101"
return = 0
Remove the first 01, then remove the remaining 01.
Example 2
s = "11100"
return = 1
Two opposite-bit pairs can be removed, leaving one 1.

Constraints
0 <= s.length <= 100000.
Every character of s is 0 or 1.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Each removal takes out exactly one 0 and one 1. So the count of zeros and ones drops by one each time. You can always keep removing until the string is all one character, because any string with both bits has some adjacent 01 or 10 somewhere. That means the answer is |count0 - count1|. Check example 2: three 1s, two 0s, answer 1. Check example 1: two and two, answer 0. The common pitfall is building a stack or doing repeated string replace, which works but is slower and easier to bug on an empty string. The stack version is still fine at O(n), just unnecessary. Handle length 0 by returning 0, which the formula does for free. If you freeze on the live OA, StealthCoder can hand you the one-pass count so you spend your time on edge cases instead.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Minimum Binary String Length After Pair Removals 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Pinecone reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Binary String Length After Pair Removals FAQ

What's the trick in Minimum Binary String Length After Pair Removals?+

Every removal deletes one 0 and one 1, so the difference between their counts never changes. You can always keep removing while both bits exist. The answer is the absolute difference between the number of zeros and ones. No simulation needed.

Why does brute force fail here?+

The string can be 100000 characters long. Scanning for a removable pair, deleting it, and rescanning is O(n^2) in the worst case, which is around 10^10 operations. The counting formula runs in O(n) with a single pass and O(1) extra space.

Can I solve it with a stack instead?+

Yes. Push each character, and if the top differs from the current one, pop. The final stack size is the answer. It's O(n) and correct, but the count difference is shorter and has fewer ways to go wrong under pressure.

What edge cases should I test?+

Test the empty string, which returns 0. Test a string of all the same bit, like 11111, which returns its full length. Test perfectly alternating strings, and strings like 1100 where the pairs aren't adjacent at first but still fully cancel.

How do I prepare for this in 48 hours?+

Write the count-difference solution once from memory and the stack version once to confirm they match. Run both on the two examples and the empty string. That's about twenty minutes. Then spend the rest of your time on other common string and counting patterns.

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

OA at Pinecone?
Invisible during screen share
Get it