Blur a Grayscale Photos Thumbnail With a Three by Three Average
Last updated: November 29, 2026
Quick Overview
Given a grayscale thumbnail as an m x n grid of integer pixel values, return a new grid where each pixel is the floor of the average of itself and its in-bounds neighbors in the surrounding 3 x 3 window.
0
0
0 solved
Given a grayscale thumbnail as an m x n grid of integer pixel values, return a new grid where each pixel is the floor of the average of itself and its in-bounds neighbors in the surrounding 3 x 3 window.
An image-flavored warm-up tied to Google Photos thumbnails. The interviewer checks careful boundary handling, that you do not overwrite pixels you still need, and whether you can talk about making the filter cheaper for large kernels.
What the Interviewer Expects
- Writes results into a separate output grid (or explains in-place encoding)
- Counts only in-bounds neighbors for border pixels
- Uses integer floor division correctly
- States O(mn) time for a fixed 3 x 3 kernel
- Mentions prefix sums for larger kernels
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Do it in place with O(1) extra memory if pixels are 0 to 255.
- The kernel is k x k for large k; how do you keep it fast?
- How would you apply this to an image too big for memory, tile by tile?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
img, an m x n list of lists of non-negative ints. - Output: a new m x n grid; cell
(r, c)becomesfloor(sum / count)over the up to nine cells(r+dr, c+dc)withdr, dcin {-1, 0, 1}...
High-Level Design
Visit every pixel, loop over the 3 x 3 window, skip out-of-range coordinates, and accumulate both the sum and the count. Write into a fresh grid so later pixels still read the original values.
For a ...