Uh oh!
There was an error while loading. Please reload this page.
added a problem on kadane's algo and its solution. - #8569
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
Uh oh!
There was an error while loading. Please reload this page.
tianyizheng02
left a comment
There was a problem hiding this comment.
Better to place this in an existing directory rather than creating a new directory for it
rohan472000
commented
Mar 30, 2023
@tianyizheng02 , there is no existing directory for this algo |
tianyizheng02
commented
Mar 30, 2023
We don't make separate directories for each algorithm in this repo. Algorithms are grouped based on general categories such as dynamic programming, machine learning, sorting algorithms, etc. My point is that you should place your new algorithm file in the same directory as similar algorithms. |
rohan472000
commented
Mar 30, 2023
ohh...will do it how to change the directory now?? |
…g/max_product_subarray.py
| n = len(nums) | ||
| if n == 0: | ||
| return 0 |
There was a problem hiding this comment.
| n=len(nums) | |
| ifn==0: | |
| return0 | |
| ifnotnumbers: | |
| return0 |
There was a problem hiding this comment.
'n' is the length of nums list , so it will always be a number.
There was a problem hiding this comment.
We do not need it until line 23 so let's not run the len() function before we need it.
There was a problem hiding this comment.
it's an edge case, so we need to check it first.. rather than going to next step.
There was a problem hiding this comment.
We can check it in two lines not three and without a function call.
| max_till_now = nums[0] | ||
| min_till_now = nums[0] | ||
| max_prod = nums[0] |
There was a problem hiding this comment.
| max_till_now=nums[0] | |
| min_till_now=nums[0] | |
| max_prod=nums[0] | |
| max_till_now=min_till_now=max_prod=numbers[0] |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| if nums[i] < 0: | ||
| max_till_now, min_till_now = min_till_now, max_till_now | ||
| max_till_now = max(nums[i], max_till_now * nums[i]) | ||
| min_till_now = min(nums[i], min_till_now * nums[i]) |
There was a problem hiding this comment.
| ifnums[i] <0: | |
| max_till_now, min_till_now=min_till_now, max_till_now | |
| max_till_now=max(nums[i], max_till_now*nums[i]) | |
| min_till_now=min(nums[i], min_till_now*nums[i]) | |
| number=numbers[i] | |
| ifnumber<0: | |
| max_till_now, min_till_now=min_till_now, max_till_now | |
| max_till_now=max(number, max_till_now*number]) | |
| min_till_now=min(number, min_till_now*number) |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
Uh oh!
There was an error while loading. Please reload this page.
| if numbers is None or not isinstance(numbers, list): | ||
| return 0 | ||
| n = len(numbers) | ||
| if n == 0: | ||
| return 0 | ||
| if not all(isinstance(x, int) for x in numbers): | ||
| return 0 |
There was a problem hiding this comment.
It is the Pythonic thing to do to raise a TypeError if the caller passes in garbage data.
| ifnumbersisNoneornotisinstance(numbers, list): | |
| return0 | |
| n=len(numbers) | |
| ifn==0: | |
| return0 | |
| ifnotall(isinstance(x, int) forxinnumbers): | |
| return0 | |
| ifnotnumbers: | |
| return0 | |
| ifnotisinstance(numbers, (list, set, tuple)) ornotall(isinstance(number, int) fornumberinnumbers): | |
| raiseTypeError("numbers must be an iterable of integers") |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rohan472000
commented
Mar 30, 2023
@cclauss , I have committed all your requests, but still the build is failing , why? |
On your local machine type https://github.com/TheAlgorithms/Python/actions/runs/4561456657/jobs/8047431889?pr=8569#step:6:657 |
rohan472000
commented
Mar 30, 2023
here is the problem, this is returning float but int is needed. what should i return if there is float in numbers, print invalid??? |
cclauss
commented
Mar 30, 2023
Raise TypeError #8569 (comment) |
rohan472000
commented
Mar 30, 2023
raised the type error, but still build is failing |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Christian Clauss <cclauss@me.com>
Uh oh!
There was an error while loading. Please reload this page.
for more information, see https://pre-commit.ci
Co-authored-by: Christian Clauss <cclauss@me.com>
cclauss
left a comment
There was a problem hiding this comment.
Modified because max_product_subarray("ABC") should not return 0.
rohan472000
commented
Mar 31, 2023
@cclauss , Thanks for the required modification. |
cclauss
commented
Mar 31, 2023
Thanks for your contribution. |
* added kadane's algorithm directory with one problem's solution. * added type hints * Rename kaadne_algorithm/max_product_subarray.py to dynamic_programming/max_product_subarray.py * Update dynamic_programming/max_product_subarray.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update max_product_subarray.py * Update max_product_subarray.py * Update dynamic_programming/max_product_subarray.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update max_product_subarray.py * Update max_product_subarray.py * Update max_product_subarray.py * Update max_product_subarray.py * Update max_product_subarray.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update max_product_subarray.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update max_product_subarray.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update max_product_subarray.py * Update max_product_subarray.py * Update dynamic_programming/max_product_subarray.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dynamic_programming/max_product_subarray.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update max_product_subarray.py --------- Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.