LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 87ms, memory 29.8MB, accepted 2026-01-01.

python
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

Source