Reported April 2026
Uberarray

Balanced Permutation Subarrays

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

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

Uber flagged this one in April 2026, and the input size is the whole story. With n up to 2 * 10^5, you can't check every subarray for every k. That's O(n^3) if you're sloppy, and even O(n^2) dies here. It's a permutation problem with a position-tracking trick, and once you see it, the code is about ten lines. If you blank during the real OA, StealthCoder runs invisibly on your desktop as a safety net and hands you the approach. But the idea is simple enough to own before you sit down.

The problem

You are given a permutation p of size n. For each value k from 1 to n, determine whether there exists a contiguous subarray whose elements form a permutation of the integers from 1 to k.
Return a binary string of length n. The k-th character is '1' if k is balanced, and '0' otherwise.

Function
countBalancedNumbers(p: int[]) → String

Examples
Example 1
p = [1, 3, 2, 4]
return = "1011"
For k=1, the subarray [1] works. For k=2, no contiguous subarray contains exactly {1,2}. For k=3, [1,3,2] works, and for k=4, the full array works.
Example 2
p = [3, 1, 2, 4]
return = "1111"
Each set {1..k} appears as a contiguous subarray for every k from 1 to 4.
Example 3
p = [4, 1, 3, 2]
return = "1011"
For k=1, the subarray [1] works. For k=2, no contiguous subarray forms exactly {1,2}. For k=3, the subarray [1,3,2] works, and for k=4, the entire array works.

Constraints
1 <= p.length <= 2 * 10^5
p is a permutation of integers from 1 to p.length.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: p is a permutation, so every value appears once. Store pos[v], the index of each value. For each k, track the min and max of pos[1..k] as you sweep k upward. The values 1..k form a contiguous subarray exactly when max - min + 1 == k. Since the k values are distinct and occupy k distinct positions, a span of length k means they fill it completely. That's O(n) total with one pass and two running variables. The common pitfall is simulating windows or sorting each prefix, which blows the constraint. Another slip is off-by-one on the span, or mixing up values and indices. Check Example 1: pos of 1,2,3 is 0,2,1. For k=2 the span is 0..2, length 3, not 2, so it's '0'. Build the string with a list and join it, don't concatenate in a loop. StealthCoder is your hedge if the min/max insight escapes you under the clock.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Balanced Permutation Subarrays 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Uber reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Balanced Permutation Subarrays FAQ

What's the trick in Balanced Permutation Subarrays?+

Record the position of each value. As k grows from 1 to n, keep the running min and max of those positions. If max - min + 1 equals k, then 1..k sits in one contiguous block, so k is balanced. It's a single linear pass.

How hard is this Uber OA question really?+

Medium at most. The brute force is obvious, but the constraint of 2 * 10^5 kills it. The fix is one observation about permutations and span length. Once you've seen it, the implementation is short and has few edge cases.

What time complexity does the Uber reported solution need?+

O(n) time and O(n) space. You build a position array, then sweep k once. Anything O(n^2) will likely time out at n = 2 * 10^5, so avoid nested loops over subarrays or re-sorting prefixes.

What edge cases should I test before submitting?+

Test n = 1, which returns '1'. Test a sorted array, which gives all ones. Test a reversed array, which is also all ones since each prefix of values is contiguous. Then run the three given examples and confirm k=2 fails where values 1 and 2 are separated.

How do I prepare for this in 48 hours?+

Practice the position-array plus running min/max idea on a couple of permutation problems. Write this one from scratch twice, including the output string build. Focus on recognizing when distinct values let you replace a subarray check with a simple span-length check.

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

OA at Uber?
Invisible during screen share
Get it