← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given a 2-D grid representing a black-and-white image where each cell is either 0 (white) or 1 (black). You are also provided with an API function isSameObject(r1, c1, r2, c2) that returns True if the two given adjacent pixels belong to the same black object and False otherwise. Two pixels are adjacent if they share an edge (4-directional connectivity). Your task is to count the number of distinct black objects in the image. A black object is defined as a maximal set of black pixels that are connected through a path of adjacent pixels for which isSameObject returns True for every consecutive pair. You must minimize calls to isSameObject and may assume that the API is deterministic and consistent.