Invert or Blur an Image
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The OpenAI OA reported in September 2026 looks like a freebie: flip a matrix or blur it. Then the blur rules bite. A 1x1 image has no neighbors, and the average excludes the pixel itself. Rounding is also half-up. It's a matrix simulation problem, and the filter 2 branch is where candidates lose points. If you blank on the neighbor math or the rounding, StealthCoder is the safety net running invisibly during the live OA. But this one is simple enough to nail yourself if you know the three traps.
The problem
A grayscale image is represented by a rectangular integer matrix image. Each entry is a pixel value from 0 through 255. Apply the operation selected by filter and return a new matrix: If filter == 1, reflect every row across the image's vertical axis. If filter == 2, blur each pixel using the original image. Replace it with the arithmetic mean of all existing neighboring pixels among the eight surrounding positions, rounded to the nearest integer. Because values are nonnegative, a fractional part of exactly 0.5 rounds up. When a pixel has no neighbors, keep its original value. Do not use already blurred values while computing another pixel. Function applyImageFilter(image: int[][], filter: int) → int[][] Examples Example 1 image = [[1,2,3],[4,5,6]] filter = 1 return = [[3,2,1],[6,5,4]] Reflecting across the vertical axis reverses each row. Example 2 image = [[0,0,0],[0,255,0],[0,0,0]] filter = 2 return = [[85,51,85],[51,0,51],[85,51,85]] Each corner sees three neighbors, each edge-center sees five, and the center sees eight. Every average uses the original image and rounds to the nearest integer. Constraints 1 <= image.length <= 200 1 <= image[r].length <= 200 All rows have the same length. 0 <= image[r][c] <= 255 filter is 1 or 2.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Filter 1 is a row reverse, nothing more. Filter 2 is the real work. For each cell, loop over the eight offsets, skip out-of-bounds, sum values and count them. Do not include the cell itself. That's the first trap, since Example 2 shows the center becoming 0 from eight zero neighbors. Second trap: write into a new matrix so you only read original values. Third trap: rounding. Values are nonnegative, so half-up is (sum * 2 + count) / (2 * count) in integer division, which avoids float errors. If count is 0, which happens for a 1x1 image, keep the original value. Complexity is O(rows * cols * 8), trivial at 200x200. If the live OA rattles you and the edge cases slip, StealthCoder is the hedge that reads the problem and hands you a clean solution.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Invert or Blur an Image 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 OpenAI's OA.
OpenAI 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.
Invert or Blur an Image FAQ
How hard is the OpenAI Invert or Blur an Image problem really?+
Easy on algorithm, medium on care. There's no clever data structure. You lose points on the details: excluding the center pixel, using the original matrix for every average, rounding half up, and handling a pixel with no neighbors. Get those four right and you're done.
What's the trick for rounding the blur average?+
Avoid floats. Since values are nonnegative, round half up with integer math: (2 * sum + count) / (2 * count) using integer division. That gives 0.5 fractions rounding up exactly. Floating point can misround values like 2.5, so integer arithmetic is the safer choice.
Why can't I update the image in place for the blur?+
The spec says each pixel uses the original image. If you overwrite as you go, later pixels average already-blurred neighbors and your output drifts from the expected answer. Allocate a fresh result matrix and only read from the input.
What edge cases should I test before submitting?+
Test a 1x1 image with filter 2, which has no neighbors and must keep its value. Test a single row and a single column, where neighbor counts shrink. Test Example 2 for the corner, edge, and center counts. Also test filter 1 on an odd-width row.
How do I prepare for this in 48 hours?+
Write both filters from scratch once. Use a directions array for the eight offsets and a bounds check. Run the two given examples, then your edge cases. Practice the integer rounding formula until it's automatic. That's about an hour of work, not two days.