Tap here to switch tabs
Problem
Submissions

Problem: Maximize Win From Two Segments

med
30 min
Try to solve the Maximize Win From Two Segments problem.

Statement

You are given an integer array prizePositions sorted in non decreasing order, representing the coordinates of prizes placed along a number line. Multiple prizes may share the same position. You are also given an integer k.

You may choose 22 segments on the number line, each of length at most k. A segment covering the interval [a,b][a, b] has length at most k if b−a≤b - a \leq k. A prize is collected if its position lies within either of the chosen segments.

Return the maximum number of prizes you can collect.

Note: The 22 segments may overlap, but each prize can only be counted at most once.

Constraints:

  • 1≤1 \leq prizePositions.length ≤105\leq 10^5

  • 1≤1 \leq prizePositions[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9

  • prizePositions is sorted in non decreasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Win From Two Segments

med
30 min
Try to solve the Maximize Win From Two Segments problem.

Statement

You are given an integer array prizePositions sorted in non decreasing order, representing the coordinates of prizes placed along a number line. Multiple prizes may share the same position. You are also given an integer k.

You may choose 22 segments on the number line, each of length at most k. A segment covering the interval [a,b][a, b] has length at most k if b−a≤b - a \leq k. A prize is collected if its position lies within either of the chosen segments.

Return the maximum number of prizes you can collect.

Note: The 22 segments may overlap, but each prize can only be counted at most once.

Constraints:

  • 1≤1 \leq prizePositions.length ≤105\leq 10^5

  • 1≤1 \leq prizePositions[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9

  • prizePositions is sorted in non decreasing order.