Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I added those test cases to python. If someone is willing to do the same for JavaScript it would be nice.
In a real implementation you would just handle those cases seperately. With an empty alphabet always return empty output. With an alphabet of one character return the count of the character (or something similar).
As I've already written, the issue is not in the test case. Your function should return
null
in that case. There is no general way to implement Huffman encoding for less than 2 letters in an alphabet.0
or1
is assigned by the path you take and if no path is taken the code is empty.Can you give the title of the test case? I can't find the behavior in the test cases.
One thing that may seem a bit odd is, that once the frequencies have less than 2 elements it always returns
null
(Nothing
in Haskell). But it is in fact the most logical way. It's trival with zero elements in the alphabet (of course one could always return the empty string) but with one element in the alphabet the encoding is also an empty string (for all inputs with that character).Which language are you using?
This comment is hidden because it contains spoiler information about the solution
It's explained after you solve the kata. Try solving it in another way (using pop isn't mandatory) to see the explanation.