Developer Learning Wiki
  • About
  • DSA
    • Overview
    • Data Structures
    • Algorithms
    • Problems
  • System Design
    • Overview
  • Technical Blogs
    • Overview
  1. Data Structures & Algorithms
  2. Algorithms
  3. Kadane’s Algorithm
  • Data Structures & Algorithms
    • Practice Problems
      • Binary Search in Reversed Sorted Array
      • Two Sum
      • Valid Parentheses
      • Climbing Stairs
      • Longest Substring Without Repeating Characters
    • Data Structures
      • Queue
    • Algorithms
      • Binary Search
      • Kadane’s Algorithm

On this page

  • Kadane’s Algorithm
    • Explanation
    • Time Complexity
    • Space Complexity
  1. Data Structures & Algorithms
  2. Algorithms
  3. Kadane’s Algorithm

Kadane’s Algorithm

Kadane’s Algorithm

Kadane’s Algorithm is a dynamic programming algorithm to find the maximum sum of a contiguous subarray in an array.

Explanation

Kadane’s Algorithm is a dynamic programming algorithm to find the maximum sum of a contiguous subarray in an array.

int kadane(int arr[], int n) {
    int max_current = 0;
    int max_global = 0;
    for (int i = 0; i < n; i++) {
        max_current = max(arr[i], max_current + arr[i]);
        max_global = max(max_global, max_current);
    }
    return max_global;
}

Time Complexity

  • kadane is O(n) operation.

Space Complexity

  • kadane is O(1) operation.

© 2024 • Developer Learning Wiki • About •

Found an error? Please leave a comment here or submit a PR in this repository, thanks!

The best way to predict the future is to invent it.

Alan Kay

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

Martin Fowler

First, solve the problem. Then, write the code.

John Johnson

×

🚀 Happy Coding!