Kadanes Algorithm - P2
In this task, I worked on finding the maximum sum of a subarray from a given array. A subarray means a continuous sequence of elements, and the goal is to find the part of the array that gives the ...

Source: DEV Community
In this task, I worked on finding the maximum sum of a subarray from a given array. A subarray means a continuous sequence of elements, and the goal is to find the part of the array that gives the highest sum. What I Did I created a function called max_subarray_sum that takes an array as input and returns the maximum sum possible from any continuous subarray. For example: Input: [2, 3, -8, 7, -1, 2, 3] Output: 11 The result comes from the subarray [7, -1, 2, 3]. How I Solved It To solve this, I used an efficient approach where I keep updating the sum while moving through the array. I used two variables: current_sum to store the sum of the current subarray max_sum to store the maximum sum found so far I started both with the first element. Then I looped through the array starting from the second element. At each step: I checked whether it is better to continue the current subarray or start a new one from the current element Then I updated the maximum sum if needed Code def max_subarray_