1014. Best Sightseeing Pair Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [1014] Best Sightseeing Pair
3 *
4 * You are given an integer array values where values[i] represents the value of the i^th sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.
5 * The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them.
6 * Return the maximum score of a pair of sightseeing spots.
7 *  
8 * Example 1:
9 * 
10 * Input: values = [8,1,5,2,6]
11 * Output: 11
12 * Explanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11
13 * 
14 * Example 2:
15 * 
16 * Input: values = [1,2]
17 * Output: 2
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	2 <= values.length <= 5 * 10^4
23 * 	1 <= values[i] <= 1000
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/best-sightseeing-pair/
29// discuss: https://leetcode.com/problems/best-sightseeing-pair/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn max_score_sightseeing_pair(values: Vec<i32>) -> i32 {
35        0
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_1014() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.