Find the largest cluster detection in a 2D array.
Treat every nonzero cell as part of a cluster. Two cells belong to the same cluster when they are connected horizontally or vertically, not diagonally. Return the number of cells in the largest cluster.
Input: A rectangular 2D list of integers named grid.
Output: An integer representing the largest cluster size. Return 0 for an empty grid or a grid containing only zeros.
Examples:
grid = [[1, 1, 0], [0, 1, 0], [1, 0, 1]] returns 3 because the upper-left cluster contains three cells.grid = [[1, 0], [0, 1]] returns 1 because diagonal cells are not connected.Constraints: The grid is rectangular, contains at most 2,500 cells, and each cell is an integer.
def largest_cluster(grid):