6 kyu
Untangle list deletion/insertion
118iv2101
Loading description...
Mathematics
Performance
Algorithms
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.
Nice one.
the tests allocate about 1GiB as "junk" and then about another 300MiB - this still leaves 8.7GiB usable memory (yes, there's a whole 10GiB available)
without a limit of memory this becomes a completely different (and trivial) kata, and looking at recent solutions most of them use O(n) memory, and even some of the oldest ones do too even if it might have been tighter on memory then (but probably still many times what was needed).
my (presumably invalid) solution strictly speaking only needs 672KiB (1 bit each) or 42MiB with a python list (64 bits per reference)
... should the kata be retired? at best a limit could be set on the process with the
resource
module and then disallow numpy/mmap but like.. you can still use plain files or if using 672k memory then it's practically impossible to enforce. allocating nearly all of the 10GiB as resident memory takes a lot of time as far as I can tell, and again, still can't reasonably get it below 700KiB, or if just going for that 42MiB mark then it'll break when the environment changes slightly again, such as a different python version or a different vm/container config is used or if another process is changed/added/removedIn tests one test repeats 3 times always, you need to fix this.If this not a feature of course)
Hello, in my opinion this is a great kata, i rejoise this one. Dont stop with this, you really good in makeing kata;))
Great kata
Cool kata !!! thanks @iv2101
Please use new python test framework.
Done.
Really done.
No tests where the last element in the list is substituted.
Same kata as this one: https://www.codewars.com/kata/missing-and-duplicate-number/ except that that kata is currently in Javascript only.
Same in principle but much harder here because of performance requirements.
New katas are underrated in comparison to the old ones. This nice kata deserves at least 5_kyu, thanks.
Nice kata. Approved.
Very nice kata but quite difficult for 6 kyu. Any other kata that requires you take into account time and space complexity is at least 5 kyu.
I think the issue is that people who train on beta katas are stronger and therefore find the challenges less tricky. This is an issue of speed (those who solve the kata first can weigh in on the difficulty level) and also the beta nature (those who monitor katas in beta tend to be more proficient and hence give lower ratings). The kyu level is thus a biased estimate.
It might be hard to come up with a solution but the code itself is rather simple. The average ranking was 6kyu, I agreed with that and there were no comments indicating otherwise.
6 felt like the right range to me, and I'm nowhere near being able to do most of them without real effort. Good fun !
DON'T USE
test.expect
!test.expect(..., msg, allow_raise=True)
(yes, I'm a bit exceeded because I'm at my 6th implementation and it still doesn't pass while I had now idea that my code didn't return the right answer because I had systematically a time out error... And then I investigated breaking the tests manually and ended up with that below)
EDIT: Errr... You don't use test.except, actually, right? x-/ Anyway, can you explain this mess, please?
Thanks for the feedback. I've made some changes. Now I use only
Test.assert_equals
. You can generate more examples with something likearr = list(range(1, 100000)); arr[40] = arr[42]; shuffle(arr); Test.assert_equals(find_replaced(arr), (41,43))
but
shuffle
takes a lot of time.Timeout is a potential issue. I have two different solutions (O(n) complexity and O(1) memory) that pass in under 7 seconds. They do timeout sometimes when the server usage is heavy.
PS: this is my first kata, be nice;)
PPS: how do you make a multiline code box to fit that without semicolons?
thx, I'll try again later. Can you in the meantime tell me if only red users did solve it for now?
Fair question. Yes, non-Red users solved it, myself included. One solution is different from the two solutions I came up with. That said, it is unfortunately true that Red users are not bound by O(n)/O(1) requirements... One solution uses an O(n log n) sort, another takes up O(n) memory.
...any hint? Still stuck... :/
This comment has been hidden.
I just use a very simple mathematical approach. No data structure related tricks there ;-)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I'm currently working on something else, actually. I'll try later. ;)
Damn, I'm almost ashamed I didn't think about that earlier... ;-o
No worries! It's nice to see other ways of solving the problem.
I just looked at your solution, it's really a beautiful algo (never saw that before. It's quite evident after you have "seen the light"!)