6 kyu
Divide and Conquer
148 of 229saudiGuy
Loading description...
Algorithms
Arrays
Performance
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.
This comment has been hidden.
This comment has been hidden.
That did the trick, thank you.
This is a bit tricky for a 6kyu, I'd probably label it as 5kyu
Test functions are wrong, it's impossible to attempt the exercise, please fix!
Your solution outputs
false
forarr = [1, 2, 3, 6, 2, 3, 4, 7, 8], groupLen = 3
.Meanwhile, with the given array and group length, you can make:
[1,2,3], [2,3,4], [6,7,8]
which all of the groups have its' elements in consecutive number order.
The output should be
true
.Description should be language-agnostic (Regarding example part)
Very fun kata!
Pretty tricky kata to solve, well done, keep it up.
PHP
translation.
I have a solution in 6 strings and I always get a time-out. Why!? PLEASE ANSWER
This comment has been hidden.
My code works but it doesn't meet the 12 second time limit. Any ideas on improving it?
Not sure this is the point that makes your program fail, but instructions like
next_num in lst
oflst.pop(0)
are very expensive (in the first case, it may be necessary to parse the whole list to check wether the number is in, in the second case, theoretically it requires to reallocate the whole list each time the operation is performed). You may try to find more suitable datastructures for those operations...Thank you, that suggestion helped along with following the input constraints.
consecutive_nums([1,3,4,5], 2) How is this false?
you can't form a group of 2 elements with 1 (since 2 is not present in the list).
Strange task. I still do not understand about ([1,3,4,5], 2)
He means ([1,3,4,5],2) is not true because it cannot be broken down consecutively like [1,2],[3,4] or [2,3],[4,5] 2 is missing
Please c++ translation.
Javascript translation
Approved.
is it True? Description, Examples, consecutive_nums([1, 2, 3, 6, 2, 3, 4, 7, 8], 3) ➞ True, # [1, 2, 3], [2, 3, 4], [6, 7, 8]
and how this can be True? test.assert_equals(consecutive_nums([6, 6, 6, 9, 7, 8, 7, 5, 8, 5, 7, 8], 4), True)
[5, 6, 7, 8], [5, 6, 7, 8], [6, 7, 8, 9]
Both tests are fine. The numbers should be consecutive within each group.
thanks! Now got it. Need to distribute ALL the numbers in a certain order + the given list is unordered. The description is not that accurate(
This comment has been hidden.
Performance tests should be more consistent.
My solution ranges from 1366 ms to 3569 ms (20 hard tests).
oh, I just saw a lot of solutions got invalidated after your last update. I see you increased the input size by 10... Well, I guess it's still compatible with the rank, but that'd be better to get that straight before publishing.
Maybe add the performances tag, now?
Tag added. Voile's solution will still pass after increasing the recursion limit. I wasn't expecting this kata to be approved so quickly.
The kata is not approved. You can still change anything you like. EDIT: wait, someone did approve it :)
Hi dfhwze,
I'm done now. I just wanted to increase the list size after observing some incredible solutions passing the tests in less than
2 seconds1 second.This kata is now approvable:
This comment has been hidden.
added
Hi,
Cool one. Missing fixed/sample tests:
Cheers
Edit: I dug a bit more in the tests generation: as far as I can tell, they will almost never generate valid inputs where several groups are overlapping each others => that should be tweaked.
side note:
x += list(range(...))
->x += range(...)
(doesn't change anything since no performances are involved but... ;) )Added sample tests as per your instruction.
"..they will almost never generate valid inputs where several groups are overlapping each others..."
Let's shuffle the list before presenting it to the user. (By the way, I had anticipated this issue before you mentioned it, and I was expecting it from your end.)
Well, that doesn't address the problem at all, tho ;)
You could just add something like this to the inner loop of case1:
;)
ok. done.
We didn't totally understand each others, here, so I updated the kata, changing some stuff here and there (missing solution import, removed the list copy, which is useless if you compute the expected result first and you don't show the input in the assertion message).
And approved.
Cheers