Center Crop a Grayscale Image
Updated
Problem statement
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 = 1cropWidth = 2return = [[6,7]]One row and one column are removed evenly from opposite sides.
Constraints
1 <= image.length, image[i].length <= 200.1 <= cropHeight <= image.lengthand1 <= cropWidth <= image[i].length.(image.length - cropHeight)and(image[i].length - cropWidth)are even.
More Luma AI Online Assessment questions
- Build a Gaussian Blur KernelOA · Seen Jun 2026
- Impute Missing Values and Normalize ColumnsOA · Seen Jun 2026
- Minimum Euclidean Distance Between PointsOA · Seen Jun 2026
- Numerically Stable SoftmaxOA · Seen Jun 2026
- Rotate a Rectangular Image ClockwiseOA · Seen Jun 2026
- Triangle Flags from Adjacent ElementsOA · Seen Jun 2026
Similar questions at other companies
- Survey Table: Group Given an AnswerSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Query a Header-Encoded MatrixNVIDIA · OANVIDIA interview questions
- Count Pieces After Othello MovesHudson River Trading · OAHudson River Trading interview questions
- Trapped Characters in a GridAdobe · OAAdobe interview questions
- Find Zero Cells in a 2×2 GridRoblox · OARoblox interview questions
- Make Pixel Columns Strictly IncreasingMicrosoft · OAMicrosoft interview questions
- Check Matrix Reflection SymmetryIntuit · OAIntuit interview questions
- Tic-Tac-Toe Board StatusPinecone · OA
- Cherry PickupInfosys · OAInfosys interview questions