Reported September 2020
Postmantwo pointers

Configuration System

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

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

The mistake that sinks a first attempt at Postman's Configuration System, reported in September 2020, is building the whole sequence and then running a nested loop over it. With n up to 6 x 10^7, that's dead on arrival. The problem is dressed up as design, but it's a counting problem on a strictly increasing sequence: generate lengths with a formula, then count ordered pairs whose product is at most a. Two pointers does it in linear time. If you blank on the pointer direction during the live OA, StealthCoder runs invisibly as a safety net and gives you the working solution.

The problem

A building company offers wall side lengths from a strictly increasing sequence s. Generate n lengths beginning with s[0] = s0. For each 1 &le; i < n:
s[i] = ((k * s[i - 1] + b) mod m) + 1 + s[i - 1].
A rectangular house configuration chooses an ordered pair of offered lengths (s[i], s[j]). The ceiling is painted for free when s[i] * s[j] &le; a.
Return the number of ordered configurations that qualify. Because orientation matters, (x, y) and (y, x) are counted separately when x != y.

Function
variantsCount(n: int, s0: int, k: int, b: int, m: int, a: long) → long

Examples
Example 1
n = 3
s0 = 1
k = 1
b = 1
m = 2
a = 4
return = 6
The generated lengths are [1, 2, 4]. The qualifying ordered pairs are (1,1), (1,2), (1,4), (2,1), (2,2), and (4,1).
Example 2
n = 1
s0 = 2
k = 3
b = 4
m = 5
a = 3
return = 0
The only configuration has area 2 * 2 = 4, which is greater than 3.

Constraints
1 &le; n &le; 6 &times; 10^7
1 &le; s[i] &le; 10^9 for every generated value.
1 &le; k, b, m &le; 10^9
1 &le; a &le; 10^18
The answer fits in a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The sequence is strictly increasing because each step adds at least 1 to s[i-1]. That's the whole trick. For each i, the number of valid j is the count of lengths with s[j] <= a / s[i], using integer floor division. As i goes up, that threshold goes down, so one pointer moves right and the other moves left, and the total work is O(n). Sum the counts and you have the ordered total, since (x, y) and (y, x) are separate. The pitfalls: with n at 6 x 10^7 you can't afford slow memory or extra passes. Use 64-bit math for s[i] * s[j], or better, compare with a / s[i] to avoid overflow. Compute the mod step in 64-bit too, since k * s[i-1] can reach 10^18. If the pointer logic slips mid-assessment, StealthCoder is the hedge that gets you unstuck without the proctor seeing anything.

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 Configuration System 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 Postman's OA.

Postman 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.

Configuration System FAQ

What's the trick in Postman's Configuration System?+

The sequence is strictly increasing, so it's sorted for free. Use two pointers: as s[i] grows, the largest allowed s[j] shrinks. Move the right pointer left while the product exceeds a, then add the count of valid j. That's linear time, no binary search needed.

How hard is this one really?+

Medium. The statement is long and the design label is misleading, but the core is a two-pointer pair count. The real difficulty is the constraints. A quadratic loop fails at n of 6 x 10^7, and overflow in the generator or product will silently give wrong answers.

Do I need to store the whole sequence?+

Storing it makes two pointers simple, and it's the cleaner route. With 6 x 10^7 values that's real memory, so check what the limits allow. The alternative is to generate it again for the second pointer, which is trickier but avoids the array. Think about it before you code.

How do I avoid overflow?+

The generator computes k * s[i-1] + b, which can hit about 10^18, so use 64-bit integers there. For the pair check, compare s[j] against a / s[i] using floor division instead of multiplying. That keeps everything safely inside signed 64-bit range.

How do I prepare in 48 hours?+

Practice the sorted-array pair-counting pattern with two pointers until the pointer movement is automatic. Then check the example by hand: lengths [1,2,4] with a = 4 give 6 ordered pairs. Make sure you count (x, y) and (y, x) separately, including the equal pairs once.

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

OA at Postman?
Invisible during screen share
Get it