Yeah… I only scored 17 points. What a miscalculation for my original hope of 30! After reviewing my solutions and compared them to the unofficial answers to problems one and two, I realized that I had a lot of miscalculations.
Even though it’s after the competition, I always redo the parts that I did incorrectly so that I can learn from my mistakes, a cliché but it’s true. So in this post, I also have the completed questions that should now score 30 points (after checking with the test cases myself).
S1: Computer Purchase
This problem was actually quite simple now that I read it the second time. Apparently, the problem only required two if comparisons for each line during each of the for loop’s iterations.
- Check if the new value is greater than the current highest value or if the new value is equal to the current highest value but sorts alphabetically ahead.
- Same as step one but do the same for the second highest value.
Finally, in the output, I forgot to check if there’s only one line of input, e.g., there’s only one computer so it doesn’t make sense to have a first and second preference for the same computer.
In total, I think I got 13 points from this question because I forgot to delimit the output when there’s only one computer and I misread the lexicographic preference for the longer string.
S2: Huffman Encoding
Again, a simple mistake in my choice in function usage. During the competition, I used the replace() function which, unfortunately, didn’t do the replacing as I had intended.
It seems that the replace() function doesn’t work well when multiple starting terms, keys, have the same prefix (so much for the prefix-free property!). The prefix-free property only states that one key cannot be the prefix of another longer key (wish I knew this before the competition!).
Instead, a friend recommended me to try loop through every character in the binary string and each key in order to compare each character’s subsequent characters(depending on the current iteration’s key’s length) to the key. If there’s a match, a new string can simply be concatenated with the key’s representative letter.
Sadly, I only scored 4 points on this question because I used the replace() function instead of an actual algorithm.
Overall, it was simply because of misinterpretation of the question and shortcuts that led to my, well… disastrous result. If only I had a computer science dictionary during the competition.
Nevertheless, it was fun and challenging to answer these algorithm questions. Even though I probably wouldn’t be getting a certificate, it was a great learning experience and now I can reuse these algorithms for future projects!
I am a solo indie game developer and a remote freelance software developer living in Waterloo, Canada. I am currently working on an unannounced title.