Practice: Two pointers
0 of 4 solved
About these problems
Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.
- 1Target pairYou are given a target x and a list of n integers a1 ≤ a2 ≤ ... ≤ an in nondecreasing order. Determine whether there are two different positions i ≠ j with ai + aj = x. Print YES if such a pair exists, otherwise print NO.ApplyNot started
- 2Longest affordable runYou are given a limit k and a list of n positive integers a1, a2, ..., an. Find the greatest length of a block of consecutive elements whose sum is at most k. Print 0 if no nonempty block fits.ConnectNot started
- 3Count affordable runsYou are given a limit k and a list of n positive integers a1, a2, ..., an. Count all nonempty blocks of consecutive elements whose sum is at most k. Blocks at different positions count separately, even if they hold the same values.ReasonNot started
- 4At most k signalsYou are given a list of n integers a1, a2, ..., an. Find the length of the longest block of consecutive elements that contains at most k distinct values.StretchNot started