Skip to content

Commit bdeb2c4

Browse files
committed
Docs: Add description and complexities for Kadane's Algorithm (C++)
- Explains problem and approach - Time Complexity: O(n) - Space Complexity: O(1)
1 parent 6254773 commit bdeb2c4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

CPP/algorithms/dynamic_programming/kadane_Algorithm.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* Kadane's Algorithm - Maximum Subarray Sum (C++)
3+
*
4+
* Description:
5+
* Finds the maximum possible sum of a contiguous subarray within a
6+
* one-dimensional array of integers. Handles arrays with all-negative
7+
* numbers as well. Provided are two variants:
8+
* - kadane: classic approach with an all-negative safeguard
9+
* - kadane_optimized: concise variant that naturally handles all-negative arrays
10+
*
11+
* Time Complexity:
12+
* - O(n), where n is the number of elements in the array (single pass)
13+
*
14+
* Space Complexity:
15+
* - O(1), constant extra space
16+
*/
17+
118
#include <vector>
219
#include <algorithm>
320
#include <climits>

0 commit comments

Comments
 (0)