Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Intersections on the Chart

Try to solve the Maximum Number of Intersections on the Chart problem.

Statement

There is a line chart plotted on a 2D2\text{D} plane using an integer array y of length n. The chart consists of n−1n - 1 line segments connecting consecutive points (i+1,y[i])(i + 1, y[i]) and (i+2,y[i+1])(i + 2, y[i + 1]) for all 0≤i<n−10 \leq i < n - 1.

A horizontal line intersects a line segment if they share at least one common point.

Return the maximum number of intersections that a horizontal line can have with the chart.

Constraints:

  • 2≤2 \leq y.length ≤105\leq 10^5

  • 1≤1 \leq y[i] ≤109\leq 10^9

  • y[i] != y[i + 1] for i in range [0,n−2][0, n - 2]

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Intersections on the Chart

Try to solve the Maximum Number of Intersections on the Chart problem.

Statement

There is a line chart plotted on a 2D2\text{D} plane using an integer array y of length n. The chart consists of n−1n - 1 line segments connecting consecutive points (i+1,y[i])(i + 1, y[i]) and (i+2,y[i+1])(i + 2, y[i + 1]) for all 0≤i<n−10 \leq i < n - 1.

A horizontal line intersects a line segment if they share at least one common point.

Return the maximum number of intersections that a horizontal line can have with the chart.

Constraints:

  • 2≤2 \leq y.length ≤105\leq 10^5

  • 1≤1 \leq y[i] ≤109\leq 10^9

  • y[i] != y[i + 1] for i in range [0,n−2][0, n - 2]