A dockyard's digital manifest board displays container weight adjustments arranged in a grid with m rows and n columns; row i, column j holds a (possibly negative) integer reading. The board's display hardware allocates one fixed-width strip of digit slots per column, and every reading printed in that column — using ordinary decimal notation, where a leading minus sign occupies one slot — must fit within the strip's width. For each column, determine the minimum width (in slots) that lets every reading in that column display in full.
Line 1: two integers m n.
Each of the next m lines contains n space-separated integers — row i of the grid.
Print n space-separated integers: the required width of column 0, column 1, ..., column n-1, where the width of a column is the maximum, over all rows, of the number of characters needed to print that cell's value in decimal (including a leading - for negative values).
Example 1
Input
2 3 1 -2 3 1000 -2 4
Expected
4 2 1
Explanation
Column 0 has values 1 and 1000, needing widths 1 and 4, so the column needs width 4. Column 1 has -2 and -2, both needing width 2. Column 2 has 3 and 4, both needing width 1. Output: 4 2 1.
Example 2
Input
3 1 1 22 333
Expected
3
Explanation
The single column contains 1, 22, and 333, needing widths 1, 2, and 3 respectively, so the column's required width is the maximum, 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →