Ad
  • Custom User Avatar

    I added those test cases to python. If someone is willing to do the same for JavaScript it would be nice.

  • Custom User Avatar

    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).

  • Custom User Avatar

    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 or 1 is assigned by the path you take and if no path is taken the code is empty.

  • Custom User Avatar

    It expects an empty string to be returned when passing an empty string, except if the frequencies have 1 key.

    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).

  • Custom User Avatar

    Which language are you using?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    It's explained after you solve the kata. Try solving it in another way (using pop isn't mandatory) to see the explanation.