Outline of Shapes in an Image
Updated
Problem statement
A black-and-white image is given as a grid image, where 1 is an ink pixel and 0 is a background pixel. Two pixels are neighbours if they share a side (up, down, left or right; corners do not count).
The outside is every background pixel that can be reached from a background pixel on the edge of the image by moving between neighbouring background pixels. Background pixels that cannot be reached this way are closed holes, not outside.
An ink pixel is an outline pixel if it lies on the edge of the image or has an outside pixel as a neighbour. Return a grid of the same size with 1 on every outline pixel and 0 everywhere else.
Function
outlinePixels(image: int[][]) → int[][]Examples
Example 1
image = [[0,0,0,0,0,0],[0,1,1,1,1,0],[0,1,1,1,1,0],[0,1,1,0,1,0],[0,1,1,1,1,0],[0,0,0,0,0,0]]return = [[0,0,0,0,0,0],[0,1,1,1,1,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,1,1,1,1,0],[0,0,0,0,0,0]]Counting rows and columns from 0, the 4 x 4 block has a closed hole at row 3, column 3. Its 12 edge pixels touch the outside background, so they are kept. The pixels at (2, 2), (2, 3) and (3, 2) touch only ink or the closed hole, so they become 0.
Example 2
image = [[1,1,0,0],[1,1,1,0],[1,1,1,1]]return = [[1,1,0,0],[1,0,1,0],[1,1,1,1]]Ink pixels on the edge of the image count as outline. Counting from 0, pixel (1, 2) touches the outside background above it. Only (1, 1) is surrounded by ink on all four sides, so it becomes 0.
Example 3
image = [[0,0],[0,0]]return = [[0,0],[0,0]]There is no ink, so the outline is empty: every pixel is 0.
Constraints
1 <= image.length, image[i].length <= 40- All rows of
imagehave the same length. image[i][j]is0or1
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Count Enclosed Freshwater RegionsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Count Connected IslandsUber · PHONE SCREENUber interview questions
- Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
- Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)