Description
Given an array nums of integers and integer k, return the maximum sum of a pair of numbers that is less than k. If no such pair exists, return -1.
Examples
Input:
nums = [34,23,1,24,75,33,54,8], k = 60Output:
58Explanation:
34 + 24 = 58.
Input:
nums = [10, 20, 30, 40], k = 50Output:
40Explanation:
The pairs with sums less than 50 are: (10,20)=30, (10,30)=40, (10,40)=50 (not valid), (20,30)=50 (not valid), (20,40)=60 (not valid), (30,40)=70 (not valid). The maximum valid sum is 40.
Input:
nums = [5, 15, 25, 35], k = 45Output:
40Explanation:
The pairs with sums less than 45 are: (5,15)=20, (5,25)=30, (5,35)=40, (15,25)=40, (15,35)=50 (not valid), (25,35)=60 (not valid). The maximum valid sum is 40.
Constraints
- •
1 ≤ nums.length ≤ 100