Skip to content

Commit 31aea49

Browse files
committed
problem: 1732. Find the Highest Altitude
1 parent 09ce693 commit 31aea49

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

solutions/solution_1732/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 1732. [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/?envType=study-plan-v2&id=leetcode-75)
2+
3+
There is a biker going on a road trip. The road trip consists of `n + 1` points at different altitudes. The biker starts his trip on point `0` with altitude equal `0`.
4+
5+
You are given an integer array `gain` of length `n` where `gain[i]` is the **net gain in altitude** between points `i​​​​​`​ and `i + 1` for all (`0 <= i < n`). Return _the **highest altitude** of a point._
6+
7+
### **Example 1:**
8+
9+
<pre>
10+
<strong>Input:</strong> gain = [-5,1,5,0,-7]
11+
<strong>Output:</strong> 1
12+
<strong>Explanation:</strong> The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
13+
</pre>
14+
15+
### **Example 2:**
16+
17+
<pre>
18+
<strong>Input:</strong> gain = [-4,-3,-2,-1,4,3,2]
19+
<strong>Output:</strong> 0
20+
<strong>Explanation:</strong> The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.
21+
</pre>
22+
23+
### **Constraints:**
24+
25+
- `n == gain.length`
26+
- `1 <= n <= 100`
27+
- `-100 <= gain[i] <= 100`

solutions/solution_1732/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def largestAltitude(self, gain: List[int]) -> int:
6+
...
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from typing import TypedDict
2+
3+
import pytest
4+
5+
from . import Solution
6+
7+
8+
class InputDict(TypedDict):
9+
gain: list[int]
10+
11+
12+
class CaseDict(TypedDict):
13+
input: InputDict
14+
expected: int
15+
16+
17+
test_cases: list[CaseDict] = [
18+
{
19+
'input': {
20+
'gain': [-5, 1, 5, 0, -7],
21+
},
22+
'expected': 1,
23+
},
24+
{
25+
'input': {
26+
'gain': [-4, -3, -2, -1, 4, 3, 2],
27+
},
28+
'expected': 0,
29+
},
30+
]
31+
32+
33+
@pytest.mark.parametrize(
34+
'test_case',
35+
test_cases,
36+
)
37+
def test_solution(test_case: CaseDict):
38+
result = Solution().largestAltitude(**test_case['input'])
39+
assert result == test_case['expected']

0 commit comments

Comments
 (0)