Maximum Ascending Subarray Sum

Easy

Description

Given an array of positive integers nums, return the maximum possible sum of an ascending subarray. An ascending subarray is a contiguous sequence where each element is strictly greater than the previous.

Examples

Input:nums = [10,20,30,5,10,50]
Output:65
Explanation:

[5,10,50] sums to 65.

Input:nums = [3,3,7,7,10,20,7,1]
Output:37
Explanation:

[3,7,10,20] sums to 40. The first 3 is skipped since [3,3] is not strictly ascending, and the sequence stops at 20 since 7 < 20.

Input:nums = [100,1,2,3,4,5]
Output:15
Explanation:

[1,2,3,4,5] sums to 15. Even though 100 is the largest single element, the longest ascending subarray starting from index 1 gives the maximum sum.

Constraints

  • 1 ≤ nums.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!