Find max contiguous subarray sum for array with values 1..6 and one negative.
Toolliyo Coach
Progressive help: Nudge → Guide → Approach. Full solution stays behind the Solution tab.
Editor is open — no login wall to practice.
| Test | Status | Details |
|---|
Ready — edit the code above and click Run or Submit.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] a = { 1, 2, 3, 4, 5, 6, -6 };
int best = a[0], cur = a[0];
for (int k = 1; k < a.Length; k++) {
cur = Math.Max(a[k], cur + a[k]);
best = Math.Max(best, cur);
}
Console.WriteLine(best);
}
}
Prefer Coach (Nudge → Guide → Approach) before revealing. No forced signup.
Kadane's algorithm for max subarray.
Sign in to save and review your submission history. You can still Run code on the Editor tab as a guest.
Sign in