Understand Maximum Ascending Order Subarray Sum Problem

Problem : Maximum Ascending Order Subarray Sum

Given an array of positive integers nums, find the maximum sum of an ascending subarray.

  • A subarray is a contiguous sequence of numbers in the array.
  • A subarray is ascending if each number is strictly greater than the previous one.
  • A single-element subarray is also considered ascending.

Return the maximum possible sum among all ascending subarrays.


Example 1

Input:

nums = [5, 15, 25, 10, 20, 30]

Output:

60

Explanation:

The subarray [10, 20, 30] has the maximum sum of 50.


Example 2

Input:

nums = [3, 6, 9, 12]

Output:

30

Explanation:

The entire array [3, 6, 9, 12] is ascending, with a sum of 30.


Example 3

Input:

nums = [8, 7, 6, 5, 4]

Output:

8

Explanation:

Each element is in descending order, so the maximum sum is the largest single element: 8.


Example 4

Input:

nums = [2, 2, 2, 2]

Output:

2

Explanation:

All elements are equal, so no two consecutive elements form an ascending sequence. The maximum sum is any single element: 2.


Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100
Category:
  • Leetcode Problem of the Day
  • Arrays
Programming Language:
  • Java
Reference Link:

https://leetcode.com/problems/maximum-ascending-subarray-sum

Java
Output:

Loading component...

Loading component...