Binary Search Searching the answer
251. Painter's Partition
Boards stand in a row, and boards[i] is the length of board i. You have painters painters to paint them.
Each painter paints one run of boards, that is, boards that stand next to each other in the row. Every
board is painted by exactly one painter, and a board cannot be shared between two painters. A painter may also
get no boards at all.
All painters start at the same moment and work side by side. Painting one unit of length takes one unit of time, so a painter needs as much time as the total length of their boards. Return the smallest time in which all the boards can be painted.
Example 1
Input: boards = [6, 2, 9, 4, 3, 7, 5], painters = 3
15Explanation: The painters take [6, 2], [9, 4] and [3, 7, 5], and finish after 8, 13 and 15 units of time. No
way to share the boards lets all three painters finish before 15.
Example 2
Input: boards = [8, 3, 5], painters = 5
8Explanation: Three painters take one board each, and the other two have nothing to paint. The board of length 8 needs 8 units of time whoever paints it.
Example 3
Input: boards = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
painters = 2
3000000000Explanation: One of the two painters has to paint at least three of the five boards, which takes 3 × 109 units of time.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ boards.length ≤ 1051 ≤ boards[i] ≤ 1091 ≤ painters ≤ 105
Clarifying questions
What you would ask an interviewer before writing any code.