7 kyu
Simple Fun #312: Maximum Product
138 of 394myjinxin2015
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
python new test framework is required. updated in this fork
Approved
I was worrying about performance, but looking at the 'best practice' and 'smart' solutions I really shouldn't have done that. That's probably why this is a 7kyu.
The description tries to eradicate your concern by giving kind of small limits:
3 ≤ arr.length ≤ 15
-10 ≤ arr[i] ≤ 10
C++ translation kumited.
Haskell : https://www.codewars.com/kumite/5bd4c3e07645b95e4c0005f2?sel=5bd4c3e07645b95e4c0005f2
Approved. Cheers ;-)
[-1,-1,0,0] should remove 0 to get the product 1 but the solution requires to remove -1 that will get the product as -1 I suggest to add the following test. Test.assert_equals(maximum_product([-10,-10,0,0]),0)
Ah, I was wrong. The product will get 0 so -10 was the correct answer.
Testing for [5, 8, 6, -6, 2, -7, 0, -2, 8, 0, 8, -6, -1, -7] It should work for random inputs too: 0 should equal -7 i think here something wrong here or i do not understand condition of kata(if multiple all element of array result should be 0 with or without -7)?
The result is the element which should be removed. If more than one valid results exist, return the smallest one.
Agree that this is a tough 7. I didn't help myself based on how I approached it, but got it sorted out in the end. It was a good one though!
Hardest 7 kyu ever... Should be 6!!
This was tough! So many edge cases for me. Thank you for the challenge.
Thanks for your katas, always makes me thinking hard
Happy Coding
^_^
[8, -4, 9, 7, -2, -8, 2, 8, -9, 9, 2, -10, 5, 3, -9] expected: -4 got: 2
If you take out -4 then the product is -28217548800. But if you take out 2 then the product is 56435097600.
So the we shouldn't be removing -4 but 2 instead.
Can you check the Crystal version? For the same test the Ruby and Crystal versions seem to expect different answers.
The Ruby version worked fine without errors. It's only the Crystal version that is causing the above issue.
@GiacomoSorbi
Ops, just seen: done some changes, let me know now!
Good for practice . NICE
;-)
Python, Ruby and Crystal translations submitted. This time I have to admit if was more fun to brute force it :)
All approved. Cheers ;-)