FunctionRacerProblemsRace

Two Sum Less Than K

EasyTwo pointersPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems