Minimum Lines to Represent a Line Chart LeetCode solution in JavaScript

1
var minimumLines = function (stockPrices) {
2
if (stockPrices.length <= 1) return 0;
3
stockPrices.sort((a, b) => a[0] - b[0]);
4
var dates = stockPrices.map((el) => el[0]);
5
var price = stockPrices.map((el) => el[1]);
6
var count = 0;
7
for (var i = 0; i < dates.length - 2; i++) {
8
var area1 =
9
BigInt(price[i + 1] - price[i]) * BigInt(dates[i + 2] - dates[i + 1]);
10
var area2 =
11
BigInt(dates[i + 1] - dates[i]) * BigInt(price[i + 2] - price[i + 1]);
12
if (area1 !== area2) {
13
count++;
14
}
15
}
16
return count + 1;
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0