BloombergMachine Learning Engineer · Phone ScreenCodemia practiceFind connected components in matrix
Given a binary matrix, write a function to find all connected components of 1s (representing land) and return a list of these components, where each component is represented by a list of its coordinates. The function should efficiently traverse the matrix using Depth-First Search (DFS) or Breadth-First Search (BFS) to identify and group connected 1s, and the output should be a list of lists, with each inner list containing the coordinates of a connected component.