Skip to content

Commit 48452fe

Browse files
committed
1927-MAXIMUM-ASCENDING-SUBARRAY-SUM Stats: Time: 0 ms (100%), Space: 11 MB (77.09%) - LeetHub
1 parent 1cd3b88 commit 48452fe

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
int maxAscendingSum(vector<int>& nums) {
4+
int n = nums.size();
5+
6+
if(n == 1) return nums[0];
7+
8+
int maxi = 0;
9+
int sum = 0;
10+
for (int i = 0; i < n - 1; i++) {
11+
sum += nums[i];
12+
maxi = max(maxi, sum);
13+
14+
if (nums[i] >= nums[i + 1])
15+
sum = 0;
16+
}
17+
18+
if (nums[n - 2] < nums[n - 1]) {
19+
sum += nums[n - 1];
20+
}
21+
22+
maxi = max(maxi, sum);
23+
24+
return maxi;
25+
}
26+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<h2><a href="https://leetcode.com/problems/maximum-ascending-subarray-sum">1927. Maximum Ascending Subarray Sum</a></h2><h3>Easy</h3><hr><p>Given an array of positive integers <code>nums</code>, return the <em>maximum possible sum of an <strong>ascending</strong> subarray in </em><code>nums</code>.</p>
2+
3+
<p>A subarray is defined as a contiguous sequence of numbers in an array.</p>
4+
5+
<p>A subarray <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> is <strong>ascending</strong> if for all <code>i</code> where <code>l &lt;= i &lt; r</code>, <code>nums<sub>i </sub> &lt; nums<sub>i+1</sub></code>. Note that a subarray of size <code>1</code> is <strong>ascending</strong>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> nums = [10,20,30,5,10,50]
12+
<strong>Output:</strong> 65
13+
<strong>Explanation: </strong>[5,10,50] is the ascending subarray with the maximum sum of 65.
14+
</pre>
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> nums = [10,20,30,40,50]
20+
<strong>Output:</strong> 150
21+
<strong>Explanation: </strong>[10,20,30,40,50] is the ascending subarray with the maximum sum of 150.
22+
</pre>
23+
24+
<p><strong class="example">Example 3:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> nums = [12,17,15,13,10,11,12]
28+
<strong>Output:</strong> 33
29+
<strong>Explanation: </strong>[10,11,12] is the ascending subarray with the maximum sum of 33.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
37+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
38+
</ul>

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ this is readme. here i will make
1818
| [1876-map-of-highest-peak](https://github.com/TheVinaySagar/Leetcode/tree/master/1876-map-of-highest-peak) |
1919
| [1878-check-if-array-is-sorted-and-rotated](https://github.com/TheVinaySagar/Leetcode/tree/master/1878-check-if-array-is-sorted-and-rotated) |
2020
| [1895-minimum-number-of-operations-to-move-all-balls-to-each-box](https://github.com/TheVinaySagar/Leetcode/tree/master/1895-minimum-number-of-operations-to-move-all-balls-to-each-box) |
21+
| [1927-maximum-ascending-subarray-sum](https://github.com/TheVinaySagar/Leetcode/tree/master/1927-maximum-ascending-subarray-sum) |
2122
| [2145-grid-game](https://github.com/TheVinaySagar/Leetcode/tree/master/2145-grid-game) |
2223
| [2292-counting-words-with-a-given-prefix](https://github.com/TheVinaySagar/Leetcode/tree/master/2292-counting-words-with-a-given-prefix) |
2324
| [2465-shifting-letters-ii](https://github.com/TheVinaySagar/Leetcode/tree/master/2465-shifting-letters-ii) |

stats.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"leetcode":{"shas":{"README.md":{"":"c2404a790a6e79b6f906ed2dd544f18dda7261dc"},"2465-shifting-letters-ii":{"sha":"d185b9a482db6f49393149aabed8a625bb6c4d4b","difficulty":"medium"},"1895-minimum-number-of-operations-to-move-all-balls-to-each-box":{"sha":"8cf49a54282d1cc0785f31978f229b45fe17ed37","difficulty":"medium"},"1524-string-matching-in-an-array":{"sha":"1e81100d7eb5724cd55903ee2d9d62124949a6a4","difficulty":"easy"},"1029-vertical-order-traversal-of-a-binary-tree":{"sha":"233be19d0cea32f5988fad6d651954cba5c9ed45","difficulty":"hard"},"0199-binary-tree-right-side-view":{"sha":"3217ef07997f85fa8d961bc4b52603ea40379e9b","difficulty":"medium"},"3309-count-prefix-and-suffix-pairs-i":{"sha":"6f1dcc761a6930bc80b7079393535bee8875e8ed","difficulty":"easy"},"0101-symmetric-tree":{"sha":"71468a287e3dc86a1a7d1e30b92c1d32f4b8fb82","difficulty":"easy"},"0121-best-time-to-buy-and-sell-stock":{"sha":"28885475707cf6030f96ff8c6b4f34f70cae2bc8","difficulty":"easy"},"2292-counting-words-with-a-given-prefix":{"sha":"e212e615d1226f7aa1fe914321a6de10cad22ec2","difficulty":"easy"},"0236-lowest-common-ancestor-of-a-binary-tree":{"sha":"0c991325621d187084183637a371159a21446339","difficulty":"medium"},"0662-maximum-width-of-binary-tree":{"sha":"110c4ddfaa298c100c10bc2fe492f28c05cc2ee7","difficulty":"medium"},"0952-word-subsets":{"sha":"a29373661158716bb8b0ccf00e3158ba370fc293","difficulty":"medium"},"0893-all-nodes-distance-k-in-binary-tree":{"sha":"258c574ced99a128a788c3eaa0cd159c20ab3e93","difficulty":"medium"},"0222-count-complete-tree-nodes":{"sha":"6c1ff1fde6115833071a176f1ad405866db12436","difficulty":"easy"},"1502-construct-k-palindrome-strings":{"sha":"f54a64510560bfd162fa61d6793cae9cc16b372d","difficulty":"medium"},"2221-check-if-a-parentheses-string-can-be-valid":{"sha":"86ca2c40bfac3acc2e4c98f7f7620cef96e24717","difficulty":"medium"},"3455-minimum-length-of-string-after-operations":{"sha":"3d63cb0e94ee6ee5d8bde444db227e80b397a703","difficulty":"medium"},"2766-find-the-prefix-common-array-of-two-arrays":{"sha":"1f536c0b4f2a0bddd73ebf3c8a02372411662889","difficulty":"medium"},"2509-minimize-xor":{"sha":"859be97d5d5eb05646d28e37d1f57f9bee76bc38","difficulty":"medium"},"0106-construct-binary-tree-from-inorder-and-postorder-traversal":{"sha":"b251746ba3488013aaa6db4afea2f6175f0f1a56","difficulty":"medium"},"0297-serialize-and-deserialize-binary-tree":{"sha":"f31632db19b9ca20446158b4b73b5260eff612a0","difficulty":"hard"},"2792-neighboring-bitwise-xor":{"sha":"0c7f84b7ab7903d479efae54727a290528e52e3a","difficulty":"medium"},"1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid":{"sha":"7871ed4476bc954d2e44ce5efb8940b5040345ab","difficulty":"hard"},"0407-trapping-rain-water-ii":{"sha":"435cb721c56f2db44c6b235bc5304182db10371b","difficulty":"hard"},"2685-first-completely-painted-row-or-column":{"sha":"003bfba52059b42334a974f8926c961dde330c83","difficulty":"medium"},"2145-grid-game":{"sha":"10ceaba68f9e680b9c110702bce7f10038991b28","difficulty":"medium"},"1876-map-of-highest-peak":{"sha":"4ae04ec1ad12335b5ad550fd6249cd57c8610633","difficulty":"medium"},"1396-count-servers-that-communicate":{"sha":"92c1e705b7495e8ee7e1fd6027d0b9ba2aa8122f","difficulty":"medium"},"0783-search-in-a-binary-search-tree":{"sha":"d2ae96c0c9681043ea392f7b81b58ec115bdd113","difficulty":"easy"},"0784-insert-into-a-binary-search-tree":{"sha":"","difficulty":"medium"},"1558-course-schedule-iv":{"sha":"badda8021673e3e997225736414be21623410e12","difficulty":"medium"},"3439-find-minimum-diameter-after-merging-two-trees":{"sha":"eaf85fa397a1b5b21272a1c7a4dfc2a19cf30304","difficulty":"hard"},"2764-maximum-number-of-fish-in-a-grid":{"sha":"d00f05e94cc685b98a97cbb577435e2cc15e2092","difficulty":"medium"},"0684-redundant-connection":{"sha":"880ddaa2e6c6d7fd457efdfd3e5a1c962ab9b667","difficulty":"medium"},"2583-divide-nodes-into-the-maximum-number-of-groups":{"sha":"24c405e0bdc8200a64b90001e9dc5f4fb5ee5f44","difficulty":"hard"},"1036-rotting-oranges":{"sha":"0d30a8ed29926c3799eef6d17c065d0b7e94b902","difficulty":"medium"},"0854-making-a-large-island":{"sha":"67c0ad3a35f375cb21edb0fb78cacf5a278ec244","difficulty":"hard"},"3429-special-array-i":{"sha":"ef6cee63d0af1b6f4b4171c2297be6337909168b","difficulty":"easy"},"0547-number-of-provinces":{"sha":"2c88a80dfe972059ae86c77fdc3f00c62982cd4a","difficulty":"medium"},"1878-check-if-array-is-sorted-and-rotated":{"sha":"cc065e516e58d8498b50ea24f3b1a51e211b6010","difficulty":"easy"},"0733-flood-fill":{"sha":"88c20887f3a61a64055ccee8d80b855da3be9494","difficulty":"easy"},"3372-longest-strictly-increasing-or-strictly-decreasing-subarray":{"sha":"","difficulty":"easy"}},"solved":42,"easy":11,"medium":24,"hard":7}}
1+
{"leetcode":{"shas":{"README.md":{"":"e4b17c98059d06477e09dddbe1bf0037a1c8cbc6"},"2465-shifting-letters-ii":{"sha":"d185b9a482db6f49393149aabed8a625bb6c4d4b","difficulty":"medium"},"1895-minimum-number-of-operations-to-move-all-balls-to-each-box":{"sha":"8cf49a54282d1cc0785f31978f229b45fe17ed37","difficulty":"medium"},"1524-string-matching-in-an-array":{"sha":"1e81100d7eb5724cd55903ee2d9d62124949a6a4","difficulty":"easy"},"1029-vertical-order-traversal-of-a-binary-tree":{"sha":"233be19d0cea32f5988fad6d651954cba5c9ed45","difficulty":"hard"},"0199-binary-tree-right-side-view":{"sha":"3217ef07997f85fa8d961bc4b52603ea40379e9b","difficulty":"medium"},"3309-count-prefix-and-suffix-pairs-i":{"sha":"6f1dcc761a6930bc80b7079393535bee8875e8ed","difficulty":"easy"},"0101-symmetric-tree":{"sha":"71468a287e3dc86a1a7d1e30b92c1d32f4b8fb82","difficulty":"easy"},"0121-best-time-to-buy-and-sell-stock":{"sha":"28885475707cf6030f96ff8c6b4f34f70cae2bc8","difficulty":"easy"},"2292-counting-words-with-a-given-prefix":{"sha":"e212e615d1226f7aa1fe914321a6de10cad22ec2","difficulty":"easy"},"0236-lowest-common-ancestor-of-a-binary-tree":{"sha":"0c991325621d187084183637a371159a21446339","difficulty":"medium"},"0662-maximum-width-of-binary-tree":{"sha":"110c4ddfaa298c100c10bc2fe492f28c05cc2ee7","difficulty":"medium"},"0952-word-subsets":{"sha":"a29373661158716bb8b0ccf00e3158ba370fc293","difficulty":"medium"},"0893-all-nodes-distance-k-in-binary-tree":{"sha":"258c574ced99a128a788c3eaa0cd159c20ab3e93","difficulty":"medium"},"0222-count-complete-tree-nodes":{"sha":"6c1ff1fde6115833071a176f1ad405866db12436","difficulty":"easy"},"1502-construct-k-palindrome-strings":{"sha":"f54a64510560bfd162fa61d6793cae9cc16b372d","difficulty":"medium"},"2221-check-if-a-parentheses-string-can-be-valid":{"sha":"86ca2c40bfac3acc2e4c98f7f7620cef96e24717","difficulty":"medium"},"3455-minimum-length-of-string-after-operations":{"sha":"3d63cb0e94ee6ee5d8bde444db227e80b397a703","difficulty":"medium"},"2766-find-the-prefix-common-array-of-two-arrays":{"sha":"1f536c0b4f2a0bddd73ebf3c8a02372411662889","difficulty":"medium"},"2509-minimize-xor":{"sha":"859be97d5d5eb05646d28e37d1f57f9bee76bc38","difficulty":"medium"},"0106-construct-binary-tree-from-inorder-and-postorder-traversal":{"sha":"b251746ba3488013aaa6db4afea2f6175f0f1a56","difficulty":"medium"},"0297-serialize-and-deserialize-binary-tree":{"sha":"f31632db19b9ca20446158b4b73b5260eff612a0","difficulty":"hard"},"2792-neighboring-bitwise-xor":{"sha":"0c7f84b7ab7903d479efae54727a290528e52e3a","difficulty":"medium"},"1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid":{"sha":"7871ed4476bc954d2e44ce5efb8940b5040345ab","difficulty":"hard"},"0407-trapping-rain-water-ii":{"sha":"435cb721c56f2db44c6b235bc5304182db10371b","difficulty":"hard"},"2685-first-completely-painted-row-or-column":{"sha":"003bfba52059b42334a974f8926c961dde330c83","difficulty":"medium"},"2145-grid-game":{"sha":"10ceaba68f9e680b9c110702bce7f10038991b28","difficulty":"medium"},"1876-map-of-highest-peak":{"sha":"4ae04ec1ad12335b5ad550fd6249cd57c8610633","difficulty":"medium"},"1396-count-servers-that-communicate":{"sha":"92c1e705b7495e8ee7e1fd6027d0b9ba2aa8122f","difficulty":"medium"},"0783-search-in-a-binary-search-tree":{"sha":"d2ae96c0c9681043ea392f7b81b58ec115bdd113","difficulty":"easy"},"0784-insert-into-a-binary-search-tree":{"sha":"","difficulty":"medium"},"1558-course-schedule-iv":{"sha":"badda8021673e3e997225736414be21623410e12","difficulty":"medium"},"3439-find-minimum-diameter-after-merging-two-trees":{"sha":"eaf85fa397a1b5b21272a1c7a4dfc2a19cf30304","difficulty":"hard"},"2764-maximum-number-of-fish-in-a-grid":{"sha":"d00f05e94cc685b98a97cbb577435e2cc15e2092","difficulty":"medium"},"0684-redundant-connection":{"sha":"880ddaa2e6c6d7fd457efdfd3e5a1c962ab9b667","difficulty":"medium"},"2583-divide-nodes-into-the-maximum-number-of-groups":{"sha":"24c405e0bdc8200a64b90001e9dc5f4fb5ee5f44","difficulty":"hard"},"1036-rotting-oranges":{"sha":"0d30a8ed29926c3799eef6d17c065d0b7e94b902","difficulty":"medium"},"0854-making-a-large-island":{"sha":"67c0ad3a35f375cb21edb0fb78cacf5a278ec244","difficulty":"hard"},"3429-special-array-i":{"sha":"ef6cee63d0af1b6f4b4171c2297be6337909168b","difficulty":"easy"},"0547-number-of-provinces":{"sha":"2c88a80dfe972059ae86c77fdc3f00c62982cd4a","difficulty":"medium"},"1878-check-if-array-is-sorted-and-rotated":{"sha":"cc065e516e58d8498b50ea24f3b1a51e211b6010","difficulty":"easy"},"0733-flood-fill":{"sha":"88c20887f3a61a64055ccee8d80b855da3be9494","difficulty":"easy"},"3372-longest-strictly-increasing-or-strictly-decreasing-subarray":{"sha":"1cd3b8875128b889ce353aed4f71a4ef22a96804","difficulty":"easy"},"1927-maximum-ascending-subarray-sum":{"sha":"","difficulty":"easy"}},"solved":43,"easy":12,"medium":24,"hard":7}}

0 commit comments

Comments
 (0)