Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function that finds the maximum sum of a subarray in a given array.

Medium

Problem Statement

Implement a function that finds the maximum sum of a subarray in a given array.

Sample Input

[1, -2, 3, 4, -1, 2, 1, -5, 4]

Sample Output

9

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Find the maximum sum of a subarray (Kadane's algorithm) function maxSubarraySum(arr) { } console.log(maxSubarraySum([1, -2, 3, 4, -1, 2, 1, -5, 4]));
Log in or sign up to run or submit your code.Log inSign up
Input
[1, -2, 3, 4, -1, 2, 1, -5, 4]
Expected Output
9