3 kyu
Minimal Cost Binary Search Trees
98ecolban
Loading description...
Algorithms
Binary Search Trees
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.
I get this answer: Test Results: Random Tests cost -- random Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed make_min_tree -- random Test Passed Test Passed STDERR Execution Timed Out (12000 ms)
How can I understans what is going on?
Maybe this paragraph will help? https://docs.codewars.com/training/troubleshooting#timeout
del
This comment has been hidden.
Nice!
This comment has been hidden.
Updated code.
What is being evaluated in the random test cases? I keep getting Test passed but a message immediately below of the form:
"24704190 should equal 22467540"
I am pretty sure this is not the cost of the tree, but I can't find where the number comes from.
This comment has been hidden.
It looks like you you have a Tree that is None. A Tree cannot be None.
Are you sure? I don't think there is any way for my code to return a None instead of a Tree. The code in the traceback is not my code, it is code from your random test generator. I do not how me creating a None tree (even if I were) would cause that error.
I've just completed this and didn't have any problems with the final tests. You may want to check your code again.
Your code is wrong.
Good kata, good fun! High five @ecolban!
Some questions regarding the testcases of 2nd part of the problem:
tree2 = make_min_tree([a, b]) Test.assert_equals(str(tree2), '[_ A:10 [B:2]]')
tree3 = make_min_tree([a, b, c]) Test.assert_equals(str(tree3), '[_ A:10 [[B:2] C:4 ]]')
The test cases doesn't match what I understood from the question. Let me know if I am missing something.
You're dealing with BST here, and a "special kind" (as in, not usual): what defines the relation between nodes isn't the weight of the nodes, but their value, which is here the symbol/string representing the node.
So, because of this,
'[[B:2] A:10 ]'
is breaking the BST contract (B to the left of A) and isn't a possible answer.