k-th vertex (counting from one) sits at (k, heights[k - 1]), and neighbouring vertices are joined by segments. No two neighbouring vertices share a height, so there are no horizontal segments.
Draw an infinite horizontal line at any height (not necessarily an integer). Return the largest number of points where it can meet the chart. A vertex the line passes through counts as one point.heights=[2, 4, 1, 3, 2, 4] → 5
The line at height 2.5 crosses all five segments of the chart, and more than five points is impossible because the chart has only five segments.
heights=[1, 5] → 1
The chart is a single segment, so any suitable line meets it at exactly one point.
heights=[3, 1, 3, 1, 3] → 4
heights=[2, 4, 1, 3, 2, 4]
5
Run checks the first 3 tests in your browser. Submit checks all 173 tests on the server, hidden ones included.