5 kyu
Random sampling in constant time
30davilla
Loading description...
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.
Authoring Python Content: "The reference solution or data must not be defined in the Preloaded code. The reference solution must not be defined in the top-level scope of the test suite."
Please copy
verify
from Preloaded code into thetest_random()
function.test_example()
can be removed from Test Cases. It is fine to keep the existing Preloaded code for running Sample Tests.Fixed
I've featured this kata in a "Daily Beta" thing we have going on in the Codewars Discord, and a few people found the description confusing, in knowing what was actually being asked of them (ie. the actual task).
Maybe it could be slightly reworked, to more clearly state the actual task? I don't think this is a big problem (hence the 'suggestion' tag), but I thought I would at least mention it.
I've expanded the description if it helps. It feels too elaborate, so you're welcome to trim it down.
Huh? The initial solution ignores the weights, but the description example seems to implement the example weights (
[3,1,0,1,5]
) perfectly fine.Maybe I'm just not good at reading Python ( I definitely am no good at reading Python! ), but the whole section of the description under the example code seems written as if we are reading from the initial solution and not the description. But the description should be written to specify the problem, completely, before going on to the trainer. It's not clear that the
class
definition is going to be inPreloaded
and onlymake_table
is in the trainer. I did not even notice thatmake_table
was not a class method initially.Maybe split the code block in two, mark one
Preloaded
and oneSolution
or something?Yes, it's meant to work for that one example only. I've made the initial solution closer in line to avoid confusion, and implemented your suggestion about sectioning.
Should that not be
O(1)
time?Or do you mean generating the table should run in
O(n)
time, and the sampling will then run inO(1)
time?Get a random number using the table is O(1).
Generate the table (this kata) is O(n).
The latter. I've (partly) clarified this in the description now.