Same here : all tests pass, but it fails on submission for the 4th test only. The code is quite simple, weight computation seems OK, but something is obviously wrong. I am desesparte (sort of).
Shame on me. Wrong return code testing => 100% now.
The input spec clearly states : “Last line: The 7 letters available.”
But in some submission tests, there is a different number of letter on the last line. Maybe the spec should be something more like “Last line: The letters available.” and there should be somewhere something saying that there is not always 7 letters in your hand.
I just arrived at this page due to the same reason. I’m using C, and have a similar algorithm. All tests in dev pass, and all but “valid word” pass when submitting. All four large tests pass…so I’m not sure what’s up. I do handle receiving less than 7 letters as well.
It looks like the valid word test is testing what happens when the letters you get are in the right order and already form the best word.
When the first step of your algorithms is to take the letters and generate all combinations you have to make sure to include the original sequence.
That should already be happening the way my algorithm is written. I will see what happens if I prepend my generic checks with a few substring checks. Thanks for the idea.
I should also note a potential bug. The spec indicates N can approach 100,000, but in the template it is using a signed int. I haven’t run a sizeof on it, but I’m guessing it’s a 2-word, 16-bit short.
It’s 32-bit here.
Okie doke, thanks. I just redid my whole program with a diff algorithm (a lot faster, smaller mem footprint and half the sloc, yay!) still can’t pass valid word test. Scratchin’ my head.
Got 100% after adding a little magic … I am not sure that test case is compliant with the spec.
There is a test with only 6 letters, it may cause some bugs.
It’s a language-specific consideration. I’ve noticed this in many of their input files when using C; you need to do a lot of input sanitization. They send you some interesting characters…even if your algorithm is parametric.
If this is true the example test case could not pass: “which” has two ‘h’
Your proposed solution was not clear, the example solution also have doubled letters (‘which’ has two ‘h’):
Input:
5
because
first
these
could
which
hicquwh
Output
which
I have a question on elegence.
Using python I created a dictionary for the character values, and put it in a function to calculate the word value. But I was wondering if anyone can guide me to a better looking dictionary or maybe a more optimized algorithm, here goes my reasoning:
def calcWord(word):
vals = {
'e': 1, 'a': 1, 'i': 1, 'o': 1, 'n': 1,
'r': 1, 't': 1, 'l': 1, 's':1, 'u': 1,
'd': 2, 'g': 2,
'b': 3, 'c': 3, 'm': 3, 'p': 3,
'f': 4, 'h': 4, 'v': 4, 'w': 4, 'y': 4,
'k': 5,
'j': 8, 'x': 8,
'q': 10, 'z': 10
}
# later I return the sum of all the values of letters in the word
You can use the dictionary without the function. vals[“e”] will return 1.
Which witch?
Anyway my code passes all test cases but fails the two Large Dictionary validators when submitted. The suggestion of invalidating words with duplicated letters violates the example provided (the witchy ‘which’). I’ve tried that, just in case, and yeah, the first test case (the one based on the example) fails.
The wicked witch is dead, now?
Count the letters in the words.
Yeah, someday I will figure out your riddle. AFAIK I’ve been counting the letters, only scoring the first occurrence.
Riddle solved, thanks! The spec has a somewhat misleading constraint: “(a letter can only be used once)”. That made me think a letter as a class (e.g. all ‘h’), but it was, instead, as an instance, so the available letters could have more than one ‘h’ and, in this case, a word with that many ‘h’ was still valid.