6 kyu
Find a Bunch of Common Elements of Two Lists in a Certain Range
490 of 891raulbc777
Loading description...
Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Strings
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.
Java:
List
import)yes not able to pass the testcases in java
Yes, this! Especially the second one. I spent hours attempting this kata before realizing the reference implementation is the one that is wrong, not my code.
As long as the test remains broken the way they currently are, the quickfix for passing the broken tests would be to throw out all negative numbers that are also odd.
I'm guessing the mistake made was thinking that
i % 2 == 1
holds for all odd numbers; actually: a negative odd number% 2
== -1okay I forked the kata and I think I fixed it but idk how to get the fix published
fork approved, issue fixed
I optimised from passing 30 test cases to 200 test cases in python and am now running out of ideas for optimization. Is it supposed to be more optimised or is the random test case is in infinite loop causing timeout?
In java version I've not passed tests for odd numbers less than zero. For example -3 occured twice or more in arrA and arrB, but this number are not expected in final list. I've wrote "quickfix" for filtering odd numbers less than zero and pass all test. In reference solution I've found line like this "i % 2 == 1 : 0 (by odd or even)". But for numbers less than zero we take -1 for odd numbers hence negative numbers are filtered in reference solution. Maybe I've not understand this task, please check my points.
reported here as an issue
Very Important: For javascript run the tests only in Node v6.6.0 and Node v6.6.0/Babel
This Node version is not available in the dropdown
Duplicate issue
Fixed in this fork
Ruby: the solution is executed while the tests are loaded. For example,
1 / 0
results in a test loading error instead of a normal error message:Thanks for spotting the bug.
Fixed in this fork (root cause - error was being thrown outside of the it block when the user's method was called)
Also fixed in Python & JavaScript.
python new test framework is required. updated in this fork
Approved!
Ruby 3.0 should be enabled
Parameter name should be
snake_case
Both done in this fork
Python new test framework should be used
Parameter name should be
snake_case
New test framework already done in this fork
Parameter name fixed in this fork
Description should be language-agnostic
Very Important: For javascript run the tests only in Node v6.6.0 and Node v6.6.0/Babel.
should be removedDone in this fork
JS: Node v14 should be used along with its appropiate assertion tools (Mocha + Chai). Refer to this and this
Done in this fork
kata broken (python) by the new runner. Need access to the edit panel and corrections
I didn't know that. Thanks
Edited! Let me know if you could solve it.
yep, all good.
I saw another kata of mine affected: Generating Numbers From Prime Factors I
Let's see if I can fix this one, too
Just reflecting in hindsight... I had to write several functionally correct versions looking for an optimized one to deal properly with huge arrays (random tests). I was thinking that struggling with optimization this deep might be too much for level 6, in python at least.
Fun kata to solve. Thanks raul.
Nice one, but the tests are maybe a little bit too much greedy, at this time : there are several validated codes that do not work anymore, just now (too much people on codewars server, I think. At least for python). But I learned some stuff, here ! ;)
Me again... About this problem, I just saw GiacomoSorbi's one lign solution and... I wrote the same, at the beginning... But it never pass below 12s this evening... ;/
EDIT : oups, I'm wrong... His "one line" is far better than mine was !
still, this kata requires a "performance" tag.
ok. On Tuesday I'll see it. Thanks
As I can see Javascript and Ruby versions have very low runtimes. With Python we have runtimes for solutions between 6.000 and 7.000 msec. But far from 12.000 msec
But we need smart brute force algorithms.
The perf requirements should be homogeneous accross languages (as much as possible, at least).
This comment has been hidden.
Using indexOf and lastIndexOf is your time-performance problem. Find another way to figure "are there at least two?" for each item.
Thanks a lot for reply!
This is ambiguous and needs to be clarified (and tested for in the basic tests)
"They occur more than once in A and more than once in B"
Ok. I hope that now the description is clearer for you.
Hi Raul, as always good kata, for me Ruby and JS works fine;-)... Have a nice day!
Thanks Matthias for your time solving it in both languages. Upvoted (+1) (+1)
Thanks for the kata, always a pleasure, sometimes a little bit work too:-)...!
I have a solution (Ruby) that passes the basic tests, but fails the Random Tests. Whatever the problem is there should be enough basic tests that it is detected at that stage.
Random tests give no indication of what the failure was.
Also the random tests take too long to run, is it really necessary to test multiple huge arrays? What is this testing for?
One of the tags of the kata is optimization. That's why there are so many tests (almost 300), and the length of the arrays may go up to 10000. The tests are working well for Ruby as smile67 pointed out. Have a good day.
I don't think codewars is a good platform for optimization problems. I'll will be sure to look for that tag and avoid problems that have it.
This doesn't address the first part of the issue. I tracked the issue down to "They occur more than once in A and more than once in B" it would be good if the standard test cases tested for this.
I put it now as you suggested. Thanks for your time solving this kata and for your good solution that passed all the tests. :)
Does this mean "both arrays"?
I'd like to see simpler example test cases that demonstrated each of the rules.
In the process to obtain the output, the rules are applied one by one.
Please use full words in the description.
Why not:
Fun Raul! thanks!
Glad you liked it!