-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added implementatin for kadane's algorithm #1031
base: master
Are you sure you want to change the base?
Conversation
*/ | ||
|
||
export default function kadane() { | ||
let current_sum = array[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is array
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out , i forgot to add parameter to function.
* Simplest Kadane's algorithm implementation. | ||
* | ||
* @param {*[]} array | ||
* @return {number[]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return {number[]} | |
* @return {number} |
/** | ||
* Simplest Kadane's algorithm implementation. | ||
* | ||
* @param {*[]} array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {*[]} array | |
* @param {number[]} array |
|
||
// This algorithm works for both positive and negative values of the array | ||
|
||
let current_sum = array[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let current_sum = array[0]; | |
let current_sum = array[0] ?? 0; |
// This algorithm works for both positive and negative values of the array | ||
|
||
let current_sum = array[0]; | ||
let maximum_subarray_sum = array[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let maximum_subarray_sum = array[0]; | |
let maximum_subarray_sum = array[0] ?? -Infinity; |
or
let maximum_subarray_sum = array[0]; | |
let maximum_subarray_sum = array[0] ?? - Math.pow(2, 53) - 1; |
This change attempts to resolve issue #1030.
Only included the implementation of the algorithm, let me know whether i should further continue to contribute or not.
Signed-off-by : Sundaram krishnan krishnsundaram@gmail.com