java.lang.Object
g2401_2500.s2453_destroy_sequential_targets.Solution

public class Solution extends Object
2453 - Destroy Sequential Targets.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers, representing targets on a number line. You are also given an integer <code>space</code>.</p> <p>You have a machine which can destroy targets. <strong>Seeding</strong> the machine with some <code>nums[i]</code> allows it to destroy all targets with values that can be represented as <code>nums[i] + c * space</code>, where <code>c</code> is any non-negative integer. You want to destroy the <strong>maximum</strong> number of targets in <code>nums</code>.</p> <p>Return <em>the <strong>minimum value</strong> of</em> <code>nums[i]</code> <em>you can seed the machine with to destroy the maximum number of targets.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,7,8,1,1,5], space = 2</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,&hellip; In this case, we would destroy 5 total targets (all except for nums[2]). It is impossible to destroy more than 5 targets, so we return nums[3].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,3,5,2,4,6], space = 2</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> Seeding the machine with nums[0], or nums[3] destroys 3 targets. It is not possible to destroy more than 3 targets. Since nums[0] is the minimal integer that can destroy 3 targets, we return 1.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [6,2,5], space = 100</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> <li><code>1 <= space <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • destroyTargets

      public int destroyTargets(int[] nums, int space)