DEV Community

Saranya R
Saranya R

Posted on

Kadane's Algorithm

Approach Explanation (ノ◕ヮ◕)ノ*:・゚✧

  1. I started with the first element as both current_sum and max_sum.
  2. I checked each element: either add it to the current_sum or start fresh from it.
  3. I updated the max_sum whenever the current_sum became larger.
  4. I continued until the end of the array.
  5. The result was the largest possible subarray sum.

Method Used: (〜 ̄▽ ̄)〜

  • Dynamic tracking
  • Max comparison
  • Single traversal
  • No extra space

Top comments (0)