FunctionRacerProblemsRace

Best Stretch Around One Item

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

The score of a stretch of nums (one or more items next to each other) is its smallest item times its number of items.

Return the largest score among the stretches that include position k.

Example 1

nums [2,6,5,9,3]
k 2
returns 15

The stretch [6, 5, 9] has smallest item 5 and three items: 15. Growing it further lets in the 2 or the 3.

Example 2

nums [7]
k 0
returns 7

The only stretch is the single item.

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