Find the Width of Columns of a Grid

You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.

  • For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.

Return an integer array ans of size n where ans[i] is the width of the i^th column.

The length of an integer x with len digits is equal to len if x is non-negative, and len + 1 otherwise.

Example 1
  1
 22
333
Inputgrid = [[1],[22],[333]]
Output[3]
In the 0^th column, 333 is of length 3.
Example 2
-15   1   3
 15   7  12
  5   6  -2
Inputgrid = [[-15,1,3],[15,7,12],[5,6,-2]]
Output[3,1,2]
In the 0^th column, only -15 is of length 3; in the 1^st column, all integers are of length 1; in the 2^nd column, both 12 and -2 are of length 2.

Constraints

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 100
  • -10^9 <= grid[r][c] <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate