I don’t know what is in the validator (only CG does, and they ain’t telling) so I can’t say for sure what the problem is. However, your code has a couple of problems.
Try these 2 test cases:
2
flea
lead
flead
(should be flea)
2
ccow
cow
coww
(should be cow)
Hopefully that’ll help you find the problem. Let me know if you need more assistance.
I was also stuck on this for ages, scratching my head wondering why all the tests passed, except the “Valid word” submission test. It was only by searching and finding this forum post, that I discovered that one of the input tests could be using less than 7 letters. I agree that the puzzle description ought to be updated to mention that the last line might not give you a full 7 letters!
In terms of scoring a word, I wrote this (in Python), which IMHO looks quite neat
On the last test the Large dictionary 2 I keep running in to the problem of equivalent words.
The letters chosen are “retpasn”
The words that work are:
napster 9
pastern 9
The answer only recognizes “pastern” even though the 2 words are the same score. Not sure how to get the answer the validator would like. All the other tests pass without issue.
Thanks
If you use a stable_sort then the correct answer is given. I believe this is an error since it relies on the order of the words in the dictionary. This should be a stipulation in the question if that is what is intended.
From the problem description:
A dictionary of authorized words is provided as input for the program. The program must find the word in the dictionary which wins the most points for the seven given letters (a letter can only be used once). If two words win the same number of points, then the word which appears first in the order of the given dictionary should be chosen.
My code works fine and passes every test, however, I am quite certain that one possible test case would fail:
Take ‘arrest’ for example: My code is most certainly not capable at the moment to ensure that two ‘r’ are available in the given letters to form words with. It is capable of running every test case, though, which is due to the fact, that I check the word length and given letter’s length. This makes it possible to circumvent a check for multiple letters without actually being able to form it.
However, as from what I have seen so far, this case has not been testing in any of the available test?
Or am I missing something?
I pass all the test in the editor, but I don’t pass the last blind test, and I have no way to know why. I’m in c++, does anyone have a solution or a way to understand why ? (I’m in c++).
I already check if the dictionary word has less or egal number of letter than the player get.
Is that could be the time of the execution ? (but I pass all the other large dico)
Checking others’ solutions I noticed that many took the approach of going through the dictionary to get the first highest valued word that could be wirtten with the given letters.
While this is fine for the CodinGame practice, I took another approach thinkinga about the real scrabble game. In that case, the dictionary would have been fixed once for all and the cost of seting it up doesn’t matter (as it can be done once for all before any game). The problem, then, would be to check as fast as possible all the possible word against the dictionary.
This means spending only log(N) to search into the dictionary rather than N.
I solved it using this approach and I wonder if anyone did the same or rejected it for some reason.
I only checked some of the C solutions as I only did it in C.
(Of course I do not go through all the 1 * 7! +7 * 6! +21 * 5! + 35 * 4! + 35 * 3! + 21 * 2! + 7 words! )
Because you could do it with just 127 words .
It could have been even less ( considering a letter may occur multiple times) but I deemed the saving was not worthy the extra work.
I don’t understand why my algo is wrong for Valid Word test case.
I get following scores for these words:
Words [‘qzyoq’, ‘azejuy’, ‘kqjsdh’, ‘aeiou’, ‘qsjkdh’]
Scores [21, 13, 10, 5, 10]
So the winner is obviously ‘qzyoq’ (q 10+ z 10+ o 1) but the test case replies it’s ‘aeiou’.
Any hints ?
There is only one ‘q’ and no ‘y’ among those given for the “Valid Word” test case. So, even if its value would be higher, you can’t form the word ‘qzyoq’.
If you only have 1 ‘q’ and no ‘y’, how can you write ‘qzyoq’ with that?
In test 7 you miss several letters as ‘n’, ‘v’, ‘l’ and ‘y’ to write the word you propose.