FastPrepFlip, Invert, and Smooth a Binary Image
Problems/Flip, Invert, and Smooth a Binary Image

Flip, Invert, and Smooth a Binary Image

Abridge logoAbridge● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report combines horizontal flip-and-invert with image smoothing. The judged contract fixes their order and uses a fresh output matrix; the core task matches the visible source at about 85%.

Given a rectangular binary matrix image, perform two transformations without modifying the input.

  1. Flip every row horizontally, then invert each bit.
  2. For each cell of that transformed matrix, compute the floor of the average of the cell and all valid neighbors in its surrounding 3 x 3 region.

Return the smoothed matrix. Every smoothing average must read from the complete flipped-and-inverted matrix, not from partially written output.

Function

flipInvertAndSmooth(image: int[][]) → int[][]

Examples

Example 1

image = [[0,0,0],[0,0,0],[1,0,0]]return = [[1,1,1],[1,0,0],[1,0,0]]

Flipping and inverting produces [[1,1,1],[1,1,1],[1,1,0]]. Each result cell is the floored neighborhood average of that complete intermediate matrix.

Example 2

image = [[0,0],[0,0]]return = [[1,1],[1,1]]

The first transformation produces all ones, and every valid neighborhood therefore averages to one.

Example 3

image = [[1]]return = [[0]]

The single bit becomes zero; its one-cell neighborhood also averages to zero.

Constraints

  • 1 <= image.length, image[i].length <= 200.
  • Every row has the same length.
  • Every cell is 0 or 1.

More Abridge problems

  • Blood Type Inheritance: Possible Parent GenotypesOA · Seen Nov 2026
  • Decode Three Interleaved LinesOA · Seen Nov 2026
  • Identification Number Check DigitOA · Seen Nov 2026
All Abridge interview questionsSee Abridge hiring insights
Saved
class Solution {
    public int[][] flipInvertAndSmooth(int[][] image) {
        // Write your code here.
    }

}
Checking account…