Apple | Onsite | Find max columns in Table Layout (String Balancing)
Anonymous User
2572

Failed to solve and seeking solution here!

Return the maximum number of columns in a tabular layout of the given `items` 
where the length of each row is less than or equal to `maxWidth`.

Explanation: 
When you run `ls` command on your Terminal it would layout the items in that directory in tabulor layout.
The number of columns in the layout will be adjusted based on Terminal width. 
Here we are given the items in the directory and Terminal width, we should calculate how many columns would appear in the table layout.

Condition: Items should be listed in the same order


Input : [hello, world, onsite, developer, question]  &&  4
Output : 1

$ ls  // Terminal width: 4
hello
world
onsite
developer
question

Input : [hello, world, onsite, developer, question]  &&  18
Output : 2

$ ls  // Terminal width: 18
hello  world
onsite developer
question

![image](https://assets.leetcode.com/users/images/2aa80ffb-8cc3-4191-8336-a2312197e04a_1611127700.5059314.png)


Input : [hello, world, onsite, developer, question]  &&  28
Output : 3

$ ls  // Terminal width: 28
hello     world    onsite
developer question

![image](https://assets.leetcode.com/users/images/cb2550d7-785f-4b21-bf42-0af91506318f_1611127730.8431797.png)


Input : [hello, world, onsite, developer, question]  &&  60
Output : 5

$ ls  // Terminal width: 60
hello world onsite developer question

![image](https://assets.leetcode.com/users/images/914ab10d-ee08-4757-987d-5a2eb698db81_1611127756.5035372.png)


PS: Images are real time examples from my mac hence the order of items were modified. 
But for this problem we should not alter the items order.
Comments (7)