Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 619 Bytes

File metadata and controls

27 lines (18 loc) · 619 Bytes

Find rectangle

Instructions

Image is represent as a simple 2D array where every pixel is a 1 or a 0. The image you get is known to have a single rectangle of 0s on a background of 1s.

Write a function that takes in the image and returns list containing coordinates of top-left and bottom-right pixels represented as list of internees:

challenge.kt | solution

Examples

Example 1

val image = listOf(
    listOf(1, 1, 0, 0, 0, 1),
    listOf(1, 1, 0, 0, 0, 1),
    listOf(1, 1, 1, 1, 1, 1),
    listOf(1, 1, 1, 1, 1, 1)
)

findRectangle(image)  // [0, 2, 1, 4]