Skip to content

Commit ea5d5f3

Browse files
committed
Add solution #1732
1 parent d04ad3f commit ea5d5f3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@
357357
1672|[Richest Customer Wealth](./1672-richest-customer-wealth.js)|Easy|
358358
1679|[Max Number of K-Sum Pairs](./1679-max-number-of-k-sum-pairs.js)|Medium|
359359
1716|[Calculate Money in Leetcode Bank](./1716-calculate-money-in-leetcode-bank.js)|Easy|
360+
1732|[Find the Highest Altitude](./1732-find-the-highest-altitude.js)|Easy|
360361
1748|[Sum of Unique Elements](./1748-sum-of-unique-elements.js)|Easy|
361362
1768|[Merge Strings Alternately](./1768-merge-strings-alternately.js)|Easy|
362363
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 1732. Find the Highest Altitude
3+
* https://leetcode.com/problems/find-the-highest-altitude/
4+
* Difficulty: Easy
5+
*
6+
* There is a biker going on a road trip. The road trip consists of n + 1 points at different
7+
* altitudes. The biker starts his trip on point 0 with altitude equal 0.
8+
*
9+
* You are given an integer array gain of length n where gain[i] is the net gain in altitude
10+
* between points i and i + 1 for all (0 <= i < n). Return the highest altitude of a point.
11+
*/
12+
13+
/**
14+
* @param {number[]} gain
15+
* @return {number}
16+
*/
17+
var largestAltitude = function(gain) {
18+
return Math.max(...gain.reduce((all, n, i) => all.push(all[i] - n * -1) && all, [0]));
19+
};

0 commit comments

Comments
 (0)