Tap here to switch tabs
Problem
Submissions

Problem: Minimum Lines to Represent a Line Chart

med
30 min
Try to solve the Minimum Lines to Represent a Line Chart problem.

Statement

You are given a 22D integer array stockPrices where stockPrices[i] = [day_i, price_i] represents the price of a stock on day day_i as price_i. A line chart is created by plotting each point on a Cartesian plane and drawing straight line segments between consecutive points sorted in ascending order of their day values.

Return the minimum number of line segments required to represent the full line chart.

Constraints:

  • 1≤1 \leq stockPrices.length ≤105\leq 10^5

  • stockPrices[i].length =2= 2

  • 1≤1 \leq day_i, price_i ≤109\leq 10^9

  • All day_i are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Lines to Represent a Line Chart

med
30 min
Try to solve the Minimum Lines to Represent a Line Chart problem.

Statement

You are given a 22D integer array stockPrices where stockPrices[i] = [day_i, price_i] represents the price of a stock on day day_i as price_i. A line chart is created by plotting each point on a Cartesian plane and drawing straight line segments between consecutive points sorted in ascending order of their day values.

Return the minimum number of line segments required to represent the full line chart.

Constraints:

  • 1≤1 \leq stockPrices.length ≤105\leq 10^5

  • stockPrices[i].length =2= 2

  • 1≤1 \leq day_i, price_i ≤109\leq 10^9

  • All day_i are distinct.