leejunkim

Home

❯

leetcode

❯

arrays

❯

maximum diff between increasing elements

maximum diff between increasing elements

Apr 23, 20251 min read

  • https://leetcode.com/problems/maximum-difference-between-increasing-elements/description/
def maximumDifference(self, nums: List[int]) -> int:
	
	minVal = float('inf')
 
	diff = -1
	for n in nums:
		if n < minVal:
			minVal = min(n,minVal)
		else:
			currDiff = n - minVal
			if currDiff > 0:
				diff = max(diff, currDiff)
 
	return diff

trick

  • track the smallest number, and if the number is STRICTLY greater than the smallest num then we get the difference

Graph View

Backlinks

  • Leetcode

Created with Quartz v4.5.0 © 2025

  • GitHub
  • Discord Community