3281. Maximize Score of Numbers in Ranges Medium

@problem@discussion
#Array#Binary Search#Greedy#Sorting



1/**
2 * [3281] Maximize Score of Numbers in Ranges
3 *
4 * You are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d].
5 * You are asked to choose n integers where the i^th integer must belong to the i^th interval. The score of the chosen integers is defined as the minimum absolute difference between any two integers that have been chosen.
6 * Return the maximum possible score of the chosen integers.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">start = [6,0,3], d = 2</span>
11 * Output: <span class="example-io">4</span>
12 * Explanation:
13 * The maximum possible score can be obtained by choosing integers: 8, 0, and 4. The score of these chosen integers is min(|8 - 0|, |8 - 4|, |0 - 4|) which equals 4.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">start = [2,6,13,13], d = 5</span>
18 * Output: <span class="example-io">5</span>
19 * Explanation:
20 * The maximum possible score can be obtained by choosing integers: 2, 7, 13, and 18. The score of these chosen integers is min(|2 - 7|, |2 - 13|, |2 - 18|, |7 - 13|, |7 - 18|, |13 - 18|) which equals 5.
21 * </div>
22 *  
23 * Constraints:
24 * 
25 * 	2 <= start.length <= 10^5
26 * 	0 <= start[i] <= 10^9
27 * 	0 <= d <= 10^9
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/
33// discuss: https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn max_possible_score(start: Vec<i32>, d: i32) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_3281() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.