0% completed
Problem 4: Find the Highest Altitude(easy)
Problem Statement
A bike rider is going on a ride. The road contains n + 1 points at different altitudes. The rider starts from point 0 at an altitude of 0.
Given an array of integers gain of length n, where gain[i] represents the net gain in altitude between points i and i + 1 for all (0 <= i < n), return the highest altitude of a point.
Examples
Example 1
- Input: gain =
[-5, 1, 5, 0, -7] - Expected Output:
1 - Justification: The altitude changes are
[-5, -4, 1, 1, -6], where1is the highest altitude reached.
.....
.....
.....
cednice
· 3 years ago
If altitude array values are all negative, then initializing maxAltitude to zero will produce the incorrect answer.
tranlannhi
· 3 years ago
Would the solution with time O(logn) be better than O(n)? Could you please provide input for the following solution?
class Solution { largestAltitude(gain) { let maxAltitude = 0; let altChange = new Array(gain.length) altChange[0] = gain[0] for (let i=1; i< gain.length; i++){ altChange[i] = gain[i] + altChange[i-1] } altChange.sort((a,b) => b-a) maxAltitude = altChange[0] return maxAltitude; } }
anusha.inapakolla94
· 2 years ago
Hi Team,
May I know how many testcases each problem will be having as I could see 65 testcases are passed for one problem and 50 for another.