Reported June 2026
Luma AImatrix

Center Crop a Grayscale Image

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

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

The mistake that sinks a first attempt on Luma AI's center crop question is an off-by-one in the start index, and it's easy to make when you're rushing. This one was reported in June 2026. It's a plain array slicing problem with no clever data structure behind it. You get a 2D grid, a target height and width, and you return the middle block. The parity guarantee means the leftover rows and columns split evenly. If you've got the OA in a day or two, this is a five-minute problem you can't afford to fumble. StealthCoder is the safety net if your mind goes blank mid-assessment.

The problem

Given a rectangular grayscale image image, return its centered cropHeight × cropWidth crop.
The parity guarantees make the unused rows and columns split evenly across opposite sides.

Function
centerCrop(image: int[][], cropHeight: int, cropWidth: int) → int[][]

Examples
Example 1
image = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
cropHeight = 1
cropWidth = 2
return = [[6,7]]
One row and one column are removed evenly from opposite sides.

Constraints
1 <= image.length, image[i].length <= 200.
1 <= cropHeight <= image.length and 1 <= cropWidth <= image[i].length.
(image.length - cropHeight) and (image[i].length - cropWidth) are even.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two offsets. Top offset is (rows - cropHeight) / 2. Left offset is (cols - cropWidth) / 2. Because the constraints guarantee both differences are even, integer division is exact, so you never round. Then loop from top to top + cropHeight and slice each row from left to left + cropWidth. In Python that's image[top:top+h] with a row slice inside a comprehension. The common pitfall is using the full dimensions as the end index, or computing the offset from the crop size instead of the leftover. Another slip is swapping height and width, or reading column count from the wrong row. Check it against the example: 3 rows, crop 1, top is 1. 4 columns, crop 2, left is 1. That gives [[6,7]]. If you blank during the live OA, StealthCoder can supply the slicing logic while you verify the offsets yourself.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Center Crop a Grayscale 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Luma AI's OA.

Luma AI reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Center Crop a Grayscale Image FAQ

How hard is the Luma AI center crop problem really?+

Easy. It's index arithmetic on a 2D array with no search or DP. The only real risk is an off-by-one on the start offsets. If you can compute the leftover and halve it, you've solved the core of it.

What's the trick to center crop a grid?+

Compute top = (rows - cropHeight) / 2 and left = (cols - cropWidth) / 2. Then copy the block from those starting points for cropHeight rows and cropWidth columns. The parity guarantee means no rounding decisions are needed.

What's the time complexity?+

O(cropHeight * cropWidth), since you only copy the cells that end up in the output. Extra space is the same, because you must return a new grid. With sizes capped at 200, performance is never a concern here.

What edge cases should I test?+

Crop equal to the full image, which should return the same grid. A 1x1 crop from the middle of an odd-sized grid. A crop that trims only rows or only columns. Also check non-square images so you catch swapped height and width mistakes.

How do I prepare for this in 48 hours?+

Don't grind this one. Write the slicing solution once from memory, then run the sample by hand. Spend the rest of your time on harder grid and array problems, since this question is closer to a warm-up than a filter.

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

OA at Luma AI?
Invisible during screen share
Get it