Largest connected region

Write codeMedium25 minAmazon style

Your task

Given an m x n grid of integers, a region is a maximal group of 4-directionally connected cells that all share the same value. Return the size (number of cells) of the largest region in the grid. The grid has at least one cell. Values can be any integers including negatives.

Examples

largest_region(grid: list[list[int]]) -> int
Example 1
Inputlargest_region([[1, 1, 2], [1, 2, 2], [3, 3, 2]])
Output4