Ctrl K

Tallest After Trimming

Medium
You are given an array heights of positive integers, the heights of some columns. You may rearrange the columns in any order and trim any column down to a smaller positive integer height, as many times as you like. The final row must be tidy: the first column has height 1, and any two neighbouring columns differ in height by at most 1. Return the greatest height a column can have in such a tidy row.
Example 1
heights=[7, 1, 3, 3] → 4

Arrange them as 1, 3, 3, 7 and trim to 1, 2, 3, 4. The tallest is 4.

Example 2
heights=[2, 2, 2, 2] → 2

The first column has to be cut to 1, the rest can stay at 2: 1, 2, 2, 2.

Example 3
heights=[1000000000] → 1

The only column is first in the row, so it must become 1.

Constraints
  • 1 ≤ heights.length ≤ 10⁵
  • 1 ≤ heights[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBiggest Number From Pieces MediumStudios for Recording Sessions MediumLow, High, Low MediumStrictly Low, High, Low MediumFewest Meetings to Cancel Medium
loading Python…
Input
heights=[7, 1, 3, 3]
Expected
4

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