Maximum Ascending Subarray Sum

EasyArrays & Hashinggreedy

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given an array of positive integers nums, find the contiguous subarray that is **strictly** increasing (each element larger than the one before it) and has the largest sum. Return that sum. A single element counts as a strictly increasing subarray. Solve it in one pass.

Examples

Input: nums = [10,20,30,5,10,50]
Output: 65
[5,10,50] sums to 65, beating [10,20,30] at 60.
Input: nums = [12,17,15,13,10,11,12]
Output: 33
[10,11,12] sums to 33.
Input: nums = [100,10,1]
Output: 100
No two neighbors increase, so the best is the single element 100.

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More greedy problems