Paint the Ceiling
Reported by candidates from WeRide's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The WeRide OA reported in August 2026 looks like a geometry word problem, but it's a counting problem in disguise. Paint the Ceiling hands you a generated strictly increasing sequence and asks how many ordered pairs (i, j) give a rectangle area of at most a. The data structure it hinges on is just a sorted array and two pointers. With n up to 6 million, anything quadratic is dead on arrival. If you blank mid-assessment, StealthCoder is the safety net running invisibly on your screen.
The problem
Generate a strictly increasing sequence of n positive side lengths: s[0] = s0 For each 1 <= i < n, s[i] = ((k * s[i - 1] + b) mod m) + 1 + s[i - 1]. Count the ordered pairs of indices (i, j) such that a rectangle with side lengths s[i] and s[j] has area at most a. Both orientations count separately when the side lengths differ, and a square may use the same generated length for both sides. Return the number of qualifying ordered pairs. Function paintTheCeiling(s0: int, n: int, k: int, b: int, m: int, a: long) → long Examples Example 1 s0 = 2 n = 3 k = 3 b = 3 m = 2 a = 15 return = 5 The generated sequence is [2, 4, 6]. The qualifying ordered pairs of side lengths are (2, 2), (2, 4), (2, 6), (4, 2), and (6, 2), for a total of 5. Constraints 1 <= s0, k, b, m <= 10^9 1 <= n <= 6 * 10^6 1 <= a <= 10^18
Reported by candidates. Source: FastPrep
Pattern and pitfall
The sequence is strictly increasing by construction, since each step adds at least 1. So it's already sorted and you never need to sort it. For each i, you want the count of j with s[i] * s[j] <= a. As i grows, that count only shrinks, so one pointer moves left while the other moves right. Total work is O(n). Generate the values on the fly or store them in an array of 64-bit ints. The pitfalls are overflow and ordering. Compute k * s[i-1] + b in 64-bit, and note s can grow large, so s[i] * s[j] can pass 10^18. Compare using division, s[j] <= a / s[i], with floor division. Ordered pairs means you count every (i, j) directly, including i == j. Check against the example: [2, 4, 6] with a = 15 gives 5. If you freeze on the pointer logic during the live OA, StealthCoder can hand you the pattern.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Paint the Ceiling 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass WeRide's OA.
WeRide 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.
Paint the Ceiling FAQ
What's the trick in Paint the Ceiling?+
The sequence is strictly increasing, so it's already sorted. For each i, count the j values where s[j] <= a / s[i] using a pointer that only moves one direction as i increases. That gives O(n) instead of O(n^2).
Why can't I just use nested loops?+
n goes up to 6 * 10^6, so nested loops mean roughly 3.6 * 10^13 operations. It will time out. You need the two-pointer sweep or a binary search per index, and the two-pointer version is cleaner.
How do I avoid overflow on the area check?+
Don't multiply s[i] * s[j] when values get large. Compare s[j] <= a / s[i] using integer floor division instead. Also compute k * s[i-1] + b in 64-bit, since k and s can both be large before the mod.
Do ordered pairs and squares count twice?+
Count every (i, j) as its own pair, so (2, 4) and (4, 2) are two pairs. A pair where i equals j counts once, because it's one index pair. The example with 5 confirms this: (2,2) once, the rest twice-ish by orientation.
How should I prepare in 48 hours?+
Practice two-pointer counting on sorted arrays, especially pair-product and pair-sum thresholds. Then write the sequence generator and test the example by hand. Pay attention to 64-bit types in your language, because the overflow is where most people lose points.