less than 1 minute read

Given a list of integers nums and an integer target, return the sum of the largest pair of numbers in nums whose sum is less than target. You can assume that there is a solution.

Constraints

  • 2 ≤ n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/Sum-of-Two-Numbers-Less-Than-Target

Examples

Example 1

Input

  • nums = [5, 1, 2, 3]
  • target = 4

Output

  • answer = 3

Explanation

Sum of the largest pair of numbers less than 4 is 1 + 2 = 3.

Solution

Leave a comment