# Program to find lowest sum of pairs greater than given target in Python

PythonServer Side ProgrammingProgramming

Suppose we have a list of numbers called nums and another value target. We have to find the lowest sum of pair of numbers that is larger than target.

So, if the input is like nums = [2, 4, 6, 10, 14] target = 10, then the output will be 12, as we pick 2 and 10

To solve this, we will follow these steps −

• sort the list nums
• n := size of nums
• i := 0, j := n - 1
• while i < j, do
• if nums[i] + nums[j] > target, then
• j := j - 1
• otherwise,
• i := i + 1

Let us see the following implementation to get better understanding −

## Example

Live Demo

class Solution:
def solve(self, nums, target): nums.sort()
n = len(nums)
i, j = 0, n - 1
while i < j:
if nums[i] + nums[j] > target:
j -= 1
else:
i += 1
ob = Solution()
nums = [2, 4, 6, 10, 14]
target = 10
print(ob.solve(nums, target))

## Input

[2, 4, 6, 10, 14], 10

## Output

12
Published on 20-Nov-2020 05:39:41