Skip to content

Instantly share code, notes, and snippets.

@varenya
Created February 23, 2026 16:23
Show Gist options
  • Select an option

  • Save varenya/5ebda875032ac1ae10a16de2863c7bf8 to your computer and use it in GitHub Desktop.

Select an option

Save varenya/5ebda875032ac1ae10a16de2863c7bf8 to your computer and use it in GitHub Desktop.
function maxSubArraySum(input: number[]): number {
let maxSum = input[0];
let maxEnding = input[0];
for (let i = 1; i < input.length; i++) {
maxEnding = Math.max(maxEnding + input[i], input[i]);
maxSum = Math.max(maxSum, maxEnding);
}
return maxSum;
}
export { maxSubArraySum };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment