We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6254773 commit bdeb2c4Copy full SHA for bdeb2c4
1 file changed
CPP/algorithms/dynamic_programming/kadane_Algorithm.cpp
@@ -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
+
18
#include <vector>
19
#include <algorithm>
20
#include <climits>
0 commit comments