Skip to content

Commit 0e04873

Browse files
committed
Jun 16
1 parent a16a94f commit 0e04873

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def maximumDifference(self, nums: list[int]) -> int:
3+
min_so_far, max_diff = float('inf'), float('-inf')
4+
for num in nums:
5+
min_so_far = min(min_so_far, num)
6+
max_diff = max(max_diff, num - min_so_far)
7+
return max_diff if max_diff else -1
8+
9+
10+
def main():
11+
nums = [7, 1, 5, 4]
12+
assert Solution().maximumDifference(nums) == 4
13+
14+
nums = [9, 4, 3, 2]
15+
assert Solution().maximumDifference(nums) == -1
16+
17+
nums = [1, 5, 2, 10]
18+
assert Solution().maximumDifference(nums) == 9
19+
20+
21+
if __name__ == '__main__':
22+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| June 13 | [2616. Minimize the Maximum Difference of Pairs](https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs/) | Medium | Solved |
2020
| June 14 | []() | | |
2121
| June 15 | []() | | |
22-
| June 16 | []() | | |
22+
| June 16 | [2016. Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements/) | Easy | Solved |
2323
| June 17 | []() | | |
2424
| June 18 | []() | | |
2525
| June 19 | []() | | |
@@ -39,6 +39,6 @@
3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 2 | 2 | 0 |
42+
| Easy | 3 | 3 | 0 |
4343
| Medium | 7 | 4 | 3 |
4444
| Hard | 4 | 2 | 2 |

0 commit comments

Comments
 (0)