Destroy Sequential Targets - Problem
You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space.
You have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer.
You want to destroy the maximum number of targets in nums.
Return the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [3,6,2,4,1], space = 2
›
Output:
2
💡 Note:
Seeding with 2 destroys targets [2,4,6] (3 targets). Seeding with 1 destroys [1,3] (2 targets). Choose 2 for maximum targets.
Example 2 — Tie Breaker
$
Input:
nums = [1,3,5,2,4,6], space = 2
›
Output:
1
💡 Note:
Both remainder groups have 3 targets: [1,3,5] and [2,4,6]. Choose seed=1 (minimum value) from the first group.
Example 3 — Single Group
$
Input:
nums = [6,2,5], space = 100
›
Output:
2
💡 Note:
Since space=100 is larger than differences, each target forms its own group. Choose minimum value 2.
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i], space ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of targets and space interval
2
Process
Group targets that can be destroyed by same seed
3
Output
Minimum seed value that destroys maximum targets
Key Takeaway
🎯 Key Insight: Targets that differ by multiples of 'space' can be destroyed by the same seed
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code