Skip to content

Commit 249f5a3

Browse files
committed
Fix README and formatting
1 parent c5524bf commit 249f5a3

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

prefix-sum/pivot-index/README.md

+30-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
# 1732. Find the Highest Altitude
1+
# 724. Find Pivot Index
22

33
## Description
4-
See https://leetcode.com/problems/find-the-highest-altitude/description/
4+
See https://leetcode.com/problems/find-pivot-index/description/
55

66
## Problem
7-
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`.
7+
Given an array of integers `nums`, calculate the pivot index of this array.
88

9-
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.
9+
The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.
10+
11+
If the index is on the left edge of the array, then the left sum is `0` because there are no elements to the left. This also applies to the right edge of the array.
12+
13+
Return the leftmost pivot index. If no such index exists, return `-1`.
1014

1115
## Example 1
1216

1317
```
14-
Input: gain = [-5,1,5,0,-7]
15-
Output: 1
16-
Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
18+
Input: nums = [1,7,3,6,5,6]
19+
Output: 3
20+
Explanation:
21+
The pivot index is 3.
22+
Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11
23+
Right sum = nums[4] + nums[5] = 5 + 6 = 11
1724
```
1825

1926
## Example 2
2027

2128
```
22-
Input: gain = [-4,-3,-2,-1,4,3,2]
29+
Input: nums = [1,2,3]
30+
Output: -1
31+
Explanation:
32+
There is no index that satisfies the conditions in the problem statement.
33+
```
34+
35+
## Example 3
36+
37+
```
38+
Input: nums = [2,1,-1]
2339
Output: 0
24-
Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.
40+
Explanation:
41+
The pivot index is 0.
42+
Left sum = 0 (no elements to the left of index 0)
43+
Right sum = nums[1] + nums[2] = 1 + -1 = 0
2544
```
2645

2746
## Constraints
2847

2948
```
30-
n == gain.length
31-
1 <= n <= 100
32-
-100 <= gain[i] <= 100
49+
1 <= nums.length <= 104
50+
-1000 <= nums[i] <= 1000
3351
```

prefix-sum/pivot-index/pivot_test.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
from pivot import index
22

3+
34
def test_example_1():
45
nums = [1, 7, 3, 6, 5, 6]
56
assert index(nums) == 3
67

8+
79
def test_example_2():
810
nums = [1, 2, 3]
911
assert index(nums) == -1
1012

13+
1114
def test_example_3():
1215
nums = [2, 1, -1]
1316
assert index(nums) == 0
1417

18+
1519
def test_example_4():
1620
nums = [0, 0, 0, 0, 1]
1721
assert index(nums) == 4
1822

23+
1924
def test_example_6():
2025
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
21-
assert index(nums) == -1
26+
assert index(nums) == -1

0 commit comments

Comments
 (0)