-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Update maximum_subarray.py #7757
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
Conversation
1. Rectify documentation to indicate the correct output: function doesn't return the subarray, but rather returns a sum. 2. Make the function more Pythonic and optimal. 3. Make function annotation generic i.e. can accept any sequence. 4. Raise value error when the input sequence is empty.
I would suggest you add a hacktoberfest label to this PR. |
maximum_subarray solves one problem and maximum_subarray_sum solves a different one. It sounds like a bad idea to me to destroy an existing algorithm in order to solve a different problem. |
I think you are mistaken: |
1. Use the conventions as mentioned in pep-0257. 2. Use negative infinity as the initial value for the current maximum and the answer.
Avoid type conflict by returning the answer cast to an integer.
|
Personally, I don't like using inf. It adds a bit of noise with float/int types. Maybe get back to the simple range? for i in range(1, len(nums)):
num = nums[i] (not a blocker for merge) |
Co-authored-by: Andrey <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
True that even I don't like the additional noise and what I did seems like patchwork. So have done the requested change. Do note that this change would lead to a constant access cost for every |
Thank you. Looks like we could remove int() now and after it's good for merge. |
Remove typecast to int for the final answer
Now we are good to go for the merge. Don't forget to add the hacktoberfest label to this PR :^) |
Can anyone of you @Cjkjvfnby, @CaedenPH or @cclauss finally merge this PR into the main branch ? |
if
statements.in range(len())
constructs.nums
.nums
is empty.Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.