2640. Find the Score of All Prefixes of an Array Medium

@problem@discussion
#Array#Prefix Sum



1/**
2 * [2640] Find the Score of All Prefixes of an Array
3 *
4 * We define the conversion array conver of an array arr as follows:
5 * 
6 * 	conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.
7 * 
8 * We also define the score of an array arr as the sum of the values of the conversion array of arr.
9 * Given a 0-indexed integer array nums of length n, return an array ans of length n where ans[i] is the score of the prefix nums[0..i].
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: nums = [2,3,7,5,10]
14 * Output: [4,10,24,36,56]
15 * Explanation: 
16 * For the prefix [2], the conversion array is [4] hence the score is 4
17 * For the prefix [2, 3], the conversion array is [4, 6] hence the score is 10
18 * For the prefix [2, 3, 7], the conversion array is [4, 6, 14] hence the score is 24
19 * For the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12] hence the score is 36
20 * For the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20] hence the score is 56
21 * 
22 * <strong class="example">Example 2:
23 * 
24 * Input: nums = [1,1,2,4,8,16]
25 * Output: [2,4,8,16,32,64]
26 * Explanation: 
27 * For the prefix [1], the conversion array is [2] hence the score is 2
28 * For the prefix [1, 1], the conversion array is [2, 2] hence the score is 4
29 * For the prefix [1, 1, 2], the conversion array is [2, 2, 4] hence the score is 8
30 * For the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8] hence the score is 16
31 * For the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16] hence the score is 32
32 * For the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32] hence the score is 64
33 * 
34 *  
35 * Constraints:
36 * 
37 * 	1 <= nums.length <= 10^5
38 * 	1 <= nums[i] <= 10^9
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/find-the-score-of-all-prefixes-of-an-array/
44// discuss: https://leetcode.com/problems/find-the-score-of-all-prefixes-of-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn find_prefix_score(nums: Vec<i32>) -> Vec<i64> {
50        
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_2640() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.