Ctrl K

Table Column Widths

Easy
An integer table table has to be printed in neat columns. The width of a number is the count of characters in its decimal form, with the minus sign of a negative number counted too (-15 has width 3). The width of a column is the largest width among its numbers. Return an array whose j-th element is the width of column j.
Example 1
table=[[7, -120], [4500, 3], [-8, 66]] → [4, 4]

In the first column the widest number is 4500, at 4 characters. In the second, -120 takes 4 characters including the minus sign.

Example 2
table=[[0, 0, 0]] → [1, 1, 1]

Zero is written with a single character.

Example 3
table=[[-1], [10]] → [2]
Constraints
  • 1 ≤ len(table) ≤ 100
  • 1 ≤ len(table[i]) ≤ 100, all rows have the same length
  • -10⁹ ≤ table[i][j] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCrossword That Reads Both Ways EasyIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool Easy
loading Python…
Input
table=[[7, -120], [4500, 3], [-8, 66]]
Expected
[4, 4]

Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.