Class Solution
java.lang.Object
g2601_2700.s2640_find_the_score_of_all_prefixes_of_an_array.Solution
2640 - Find the Score of All Prefixes of an Array.<p>Medium</p>
<p>We define the <strong>conversion array</strong> <code>conver</code> of an array <code>arr</code> as follows:</p>
<ul>
<li><code>conver[i] = arr[i] + max(arr[0..i])</code> where <code>max(arr[0..i])</code> is the maximum value of <code>arr[j]</code> over <code>0 <= j <= i</code>.</li>
</ul>
<p>We also define the <strong>score</strong> of an array <code>arr</code> as the sum of the values of the conversion array of <code>arr</code>.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>, return <em>an array</em> <code>ans</code> <em>of length</em> <code>n</code> <em>where</em> <code>ans[i]</code> <em>is the score of the prefix</em> <code>nums[0..i]</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,3,7,5,10]</p>
<p><strong>Output:</strong> [4,10,24,36,56]</p>
<p><strong>Explanation:</strong></p>
<p>For the prefix [2], the conversion array is [4] hence the score is 4</p>
<p>For the prefix [2, 3], the conversion array is [4, 6] hence the score is 10</p>
<p>For the prefix [2, 3, 7], the conversion array is [4, 6, 14] hence the score is 24</p>
<p>For the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12] hence the score is 36</p>
<p>For the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20] hence the score is 56</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,1,2,4,8,16]</p>
<p><strong>Output:</strong> [2,4,8,16,32,64]</p>
<p><strong>Explanation:</strong></p>
<p>For the prefix [1], the conversion array is [2] hence the score is 2</p>
<p>For the prefix [1, 1], the conversion array is [2, 2] hence the score is 4</p>
<p>For the prefix [1, 1, 2], the conversion array is [2, 2, 4] hence the score is 8</p>
<p>For the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8] hence the score is 16</p>
<p>For the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16] hence the score is 32</p>
<p>For the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32] hence the score is 64</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>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findPrefixScore
public long[] findPrefixScore(int[] nums)
-