Oracle PMTS
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-03-20Added By Anonymous
Source: Link
Company: Oracle
Role: PMTS
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
You are given a 2D array of potentially unequal height and width containing only 0s and 1s. In that matrix, each 1 represents land and each 0 represents water. An island is defined as any number of 1s that are horizontally and vertically adjacent (but not diagonally adjacent) and that don't touch the borders of the matrix. You can think of islands as a patch of 1s. You are allowed to mutate the input matrix. Write a function that returns a modified version of the matrix where all the islands are removed.
e.g.
1 0 0 0 1
0 1 0 0 0
1 1 1 0 0
Output:
1 0 0 0 1
0 0 0 0 0
1 1 1 0 0