K32

Maximum Subarray (Kadane's Algorithm)

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: NUMERIC

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]) -> int

Input & Output Contract

Output Rule:Maksimum alt dizi toplamı.

System Constraints

1 <= sayilar.length <= 10^5
-10^4 <= sayilar[i] <= 10^4

Example 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:6
Example 2: Single Element
Input:[[1]]
Expected Output:1
Example 3: Neredeyse Tamamı Pozitif
Input:[[5,4,-1,7,8]]
Expected Output:23
Example 4: Tümü Negatif
Input:[[-1,-2,-3]]
Expected Output:-1
Loading Python Editor...
Input Parameters
[
  [
    -2,
    1,
    -3,
    4,
    -1,
    2,
    1,
    -5,
    4
  ]
]
Expected Output
6