Rasterize a Circle with Integer Pixels
Reported by candidates from Pure Storage's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Pure Storage reported this one in September 2026, and it looks friendlier than it is. The prompt hands you the midpoint circle algorithm almost line by line, so the real test is whether you implement it exactly and clean up the output. Radius goes up to 10000, so you walk only about 7000 steps and emit eight points each. No pixel-grid scan, no sqrt. If you blank on the update order or the dedup, StealthCoder is the invisible safety net running during the live OA. Here's the pattern and where people slip.
The problem
Rasterize a circle of integer radius centered at (0, 0) using the midpoint circle algorithm. Start with x = 0, y = radius, and decision value d = 1 - radius. While x <= y: Add the eight symmetric coordinates (±x, ±y) and (±y, ±x). Increase x by one. If the old decision value was negative, set d = d + 2x + 1 using the new x. Otherwise, decrease y by one and set d = d + 2(x - y) + 1 using the new values. A coordinate may be generated more than once when x = 0, x = y, or radius = 0. Return every unique generated coordinate exactly once, sorted first by ascending x and then by ascending y. Function drawCirclePixels(radius: int) → int[][] Examples Example 1 radius = 0 return = [[0,0]] The eight symmetric forms all name the origin, so deduplication leaves one pixel. Example 2 radius = 2 return = [[-2,-1],[-2,0],[-2,1],[-1,-2],[-1,2],[0,-2],[0,2],[1,-2],[1,2],[2,-1],[2,0],[2,1]] The midpoint states (0,2) and (1,2) generate the twelve unique symmetric pixels shown in sorted order. Constraints 0 <= radius <= 10000. The circle is centered at the origin. Use the exact midpoint recurrence and update order stated above. The returned coordinates must be unique and lexicographically sorted by (x, y).
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is simulation. Follow the recurrence exactly: start x=0, y=r, d=1-r. Each loop, emit the eight symmetric points, then increment x. If the old d was negative, d += 2x+1 with the new x. Otherwise y decreases, then d += 2(x-y)+1 with the new values. The pitfall is order. Check the old d before touching x or y, then use the updated values in the formula. The second pitfall is duplicates. x=0, x=y, and radius=0 all produce repeated points, so push each pixel into a set (or a sorted list, then dedupe) and sort by x, then y. Total points are roughly 8 * 0.7r, about 56000 at max, so sorting is trivial. Brute force over a (2r+1)^2 grid would be 400 million cells, and that's what the constraint rules out. If the details slip under time pressure, StealthCoder can hand you the working version during the live OA.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Rasterize a Circle with Integer Pixels 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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Pure Storage's OA.
Pure Storage reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rasterize a Circle with Integer Pixels FAQ
What's the trick in the Pure Storage circle rasterization problem?+
There's no hidden trick. The statement gives the recurrence, so you implement it literally. The work is in the update order, emitting all eight symmetric points, and deduplicating before the final sort. Get those three right and it passes.
Why can't I just loop over every pixel in a grid?+
With radius up to 10000 that grid is about 400 million cells, and you'd need a distance check for each. The midpoint walk only runs about 0.7 * radius iterations. The problem also requires the exact midpoint recurrence, so the grid scan wouldn't match anyway.
How do I handle duplicate coordinates?+
Duplicates appear when x=0, x=y, or radius=0. Store each pair in a hash set, using a string key or an encoded integer. Then convert to a list and sort by x ascending, then y ascending. Sorting first and skipping adjacent equals also works.
What's the most common bug in the d update?+
Using stale values. Save whether the old d was negative, then increment x. In the negative case, use the new x. In the other case, decrement y first, then compute 2(x-y)+1 with both new values. Mixing old and new values shifts pixels.
How should I prepare for this in 48 hours?+
Hand-trace radius 2 and confirm you get the twelve pixels in Example 2. Then trace radius 0 and radius 1 for edge cases. Write the loop, the set, and the comparator once from memory. This is a simulation problem, so an hour of tracing is enough.