2845. Find the Value of the Partition
My accepted Python solution to LeetCode problem 2845, Find the Value of the Partition, running in 87ms.
- Difficulty: Medium
- Python
- Runtime 87ms
- Memory 29.8MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 87ms, memory 29.8MB, accepted 2026-01-01.
class Solution:
def findValueOfPartition(self, nums: List[int]) -> int:
nums.sort()
# Minimum difference between max of nums1 and min of nums2
# After sorting, optimal is to have adjacent elements
# in different partitions
min_diff = float('inf')
for i in range(len(nums) - 1):
min_diff = min(min_diff, nums[i + 1] - nums[i])
return min_diff