FunctionRacerProblemsRace

Picks With Light Ends

HardTwo pointersPython, JavaScript, TypeScript, Java, C++

A pick takes one or more items of nums, from any positions. A pick is light when its smallest item plus its largest item is at most limit. In a pick of a single item, that item is both the smallest and the largest.

Return the number of light picks. Picks that use different positions count separately, even when their values are equal.

Example 1

nums [2,4,7]
limit 8
returns 3

The light picks are [2], [4] and [2, 4]. Every pick with the 7 is too heavy, and [7] alone counts 7 + 7 = 14.

Example 2

nums [5,5]
limit 9
returns 0

A single 5 counts 5 + 5 = 10, which is over the limit, and both together do too.

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