2453. Destroy Sequential Targets Medium
1/**
2 * [2453] Destroy Sequential Targets
3 *
4 * 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.
5 * 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.
6 * Return the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: nums = [3,7,8,1,1,5], space = 2
11 * Output: 1
12 * Explanation: If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,...
13 * In this case, we would destroy 5 total targets (all except for nums[2]).
14 * It is impossible to destroy more than 5 targets, so we return nums[3].
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: nums = [1,3,5,2,4,6], space = 2
19 * Output: 1
20 * Explanation: Seeding the machine with nums[0], or nums[3] destroys 3 targets.
21 * It is not possible to destroy more than 3 targets.
22 * Since nums[0] is the minimal integer that can destroy 3 targets, we return 1.
23 *
24 * <strong class="example">Example 3:
25 *
26 * Input: nums = [6,2,5], space = 100
27 * Output: 2
28 * Explanation: Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= nums.length <= 10^5
34 * 1 <= nums[i] <= 10^9
35 * 1 <= space <= 10^9
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/destroy-sequential-targets/
41// discuss: https://leetcode.com/problems/destroy-sequential-targets/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn destroy_targets(nums: Vec<i32>, space: i32) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2453() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.