K32
Maximum Subarray (Kadane's Algorithm)
Problem Statement & Objective
Given an integer array nums, find the subarray with the largest sum, and return its sum.
Function Signature (Python)
maximum_subarray_kadanes_algorithm(nums: list[int]) -> intInput & Output Contract
Output Rule:Maksimum alt dizi toplamı.
System Constraints
1 <= sayilar.length <= 10^5
-10^4 <= sayilar[i] <= 10^4Example Execution Walkthrough
sayilar = [-2, 1, -3, 4, -1, 2, 1, -5, 4] -> [4, -1, 2, 1] toplamı 6 -> cevap: 6
sayilar = [-1, -2, -3] -> tümü negatif, cevap en büyük tekil olan -1. 0 döndürmek yanlıştır.Example Test Scenarios (4)
Example 1
Input:
[[-2,1,-3,4,-1,2,1,-5,4]]Expected Output:
6Example 2: Single Element
Input:
[[1]]Expected Output:
1Example 3: Neredeyse Tamamı Pozitif
Input:
[[5,4,-1,7,8]]Expected Output:
23Example 4: Tümü Negatif
Input:
[[-1,-2,-3]]Expected Output:
-1