OpenGenus / cosmos

World's largest Contributor driven code dataset | Used in Quark Search Engine, @OpenGenus IQ, OpenGenus Visual Project
http://internship.opengenus.org
GNU General Public License v3.0
13.52k stars 3.66k forks source link

Folder online challenges-->source-->leetcode-->maximum_subarray #6775

Closed kajal-sinha02 closed 8 months ago

kajal-sinha02 commented 8 months ago

Fixes issue: Kadane Algorithm in CPP

Changes: if (max_ending + nums[i] >= nums[i]) { max_ending += nums[i]; }

Corrected Kandane Algorithm In this corrected code, we compare max_ending + nums[i] with nums[i] to determine if it's beneficial to extend the current subarray or start a new one. This way, the code correctly calculates the maximum subarray sum.

Make sure to look at the Style Guide for your language in guides/coding_style/language_name:

 https://github.com/OpenGenus/cosmos/tree/master/guides/coding_style

 Note: A coding style guide may not exist for your language, since this is still in beta.

Make sure to look at the Documentation Style Guide in guides/documentation.md:

 https://github.com/OpenGenus/cosmos/blob/master/guides/documentation_guide.md

 The document style guide may not apply for your algorithm category, you must also look at specified guide under all of the directory in the category, e.g., for project euler:

 https://github.com/OpenGenus/cosmos/blob/master/code/online_challenges/src/project_euler/documentation_guide.md