Imagine you have a powerful targeting system that can destroy targets on a number line. You're given an array nums of positive integers representing target positions, and an integer space that defines the spacing pattern.
Here's the key: when you seed your machine with any target value nums[i], it creates a chain reaction that destroys all targets at positions nums[i] + c ร space, where c can be any non-negative integer (0, 1, 2, 3, ...).
Your mission: Choose the optimal seed value that destroys the maximum number of targets. If multiple seeds can destroy the same maximum number of targets, return the smallest seed value.
Example: With targets [3, 7, 8, 1, 1, 5] and space = 2, seeding with 1 destroys targets at positions 1, 3, 5, 7, ... which captures 4 targets from our array!
Input & Output
Constraints
- 1 โค nums.length โค 105
- 1 โค nums[i] โค 109
- 1 โค space โค 109
- All elements in nums are positive integers