Dsa
Arrays
Easy
Max Sum Subarray
Write a program that finds the contiguous subarray within a one-dimensional array of numbers which has the largest sum. Print the maximum sum found.
Input format:
- The first line contains an integer n, the length of the array.
- The second line contains n space-separated integers (the array).
Output format:
- An integer representing the maximum sum of the subarray.
Example:
Input:
5
-2 1 -3 4 -1 2 1 -5 4
Output:
6
Key concepts
arrayssubarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now