Two Sum Less Than K
Look at every pair of items of nums taken from two different positions. Among the pairs whose sum is strictly less than k, return the biggest sum.
If no pair has a sum below k, return -1.
Example 1
nums [34,23,1,24,75,33,54,8]
k 60
returns 58
24 + 33 = 57 is the biggest sum under 60.
Example 2
nums [10,20,30]
k 15
returns -1
Every pair sums to 30 or more, so -1.
Constraints
1 <= len(nums) <= 301 <= nums[i] <= 1001 <= k <= 200
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.