FastPrepCenter Crop a Grayscale Image

Center Crop a Grayscale Image

Luma AI logoLuma AI● EasyFULLTIMEOA
Learn

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.length and 1 <= cropWidth <= image[i].length.
  • (image.length - cropHeight) and (image[i].length - cropWidth) are even.

More Luma AI problems

See Luma AI hiring insights
public int[][] centerCrop(int[][] image, int cropHeight, int cropWidth) {
    // Return the centered crop.
}
image[[1,2,3,4],[5,6,7,8],[9,10,11,12]]
cropHeight1
cropWidth2
expected[[6,7]]
Checking account…