Scrabble puzzle discussion

Hi. Same problem here as well. I am using C# and my solution passed all test cases. However when I submit my code it still shows that last two cases failed. The problem is that I have no idea why its happening because there is no output there. Can someone please give me some advice? Thanks.

Hi all. I am struggling with last two test cases. I mean last two test cases contain over 25k of words each and it works fineā€¦ BUT still I have a failure when I submit the solution, freaking do not get itā€¦ It looks like my code is not optimized enough. Therefore it fails on large data sets. Can someone help me please?

`

class Solution
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());

    HashSet<string> words = new HashSet<string>();
    int maxLength = 7;
    
    for (int i = 0; i < N; i++)
    {
        string W = Console.ReadLine();
        
        if(W.Length <= maxLength)
        {
            words.Add(W);
        }
    }
    
    
    string LETTERS = Console.ReadLine();


    // Write an action using Console.WriteLine()
    // To debug: Console.Error.WriteLine("Debug messages...");
    
    Dictionary<char, int> score = new Dictionary<char, int>()
    {
        {'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}
    };
    
    int max = 0;
    string maxWord = "";
    
    foreach(string word in words)
    {
        
        if(word != null)
        {
            int temp = GetScore(score, word, LETTERS);

            if(max < temp)
            {
                max = temp;
                maxWord = word;
            }
        }
    }

    Console.WriteLine(maxWord);
}


static int GetScore(Dictionary<char, int> score, string word, string LETTERS)
{

    HashSet<char> unique = new HashSet<char>(word.ToCharArray());
    
    foreach(char ch in unique)
    {
        if(!LETTERS.Contains(ch))
        {
            return 0;
        }
    }     
    
    int totalScore = 0;

    
    foreach(char ch in unique)
    {
        totalScore += score[ch];
    }
            
    return totalScore;
}

//End of Class

}

`

Look into how you handle tiebreakers (hint: you donā€™t).

From the problem description, if 2 words count for the same number of points, the one that appears first in the dictionary should be given. Note that a hashset has no ordering; the item you put into it first may or may not be the one that you look at first when you go a foreach.

Thanks, words with same score, choosing the shortest word instead of the first one made submission pass 100%. The current puzzle submission validation is wrong for large dictionary 1/2 or description is missleading:
ā€œ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.ā€

In Java to have insertion-ordered items in a HashSet, use LinkedHashSet.

There are not enough letters in playerā€™s hand for ā€œrestaurateurā€. Every letter may be used once, as intro says.

There is actually one test which is wrong. The ā€œvalid wordā€ test being run after submission, is actually giving an amount of letters which is not equal to 7.

1 Like

Youā€™re right. Weā€™ll look into it.

So I am confused. When I readline() all I am getting is the value 5 instead of the dictionary. As some who just started programming, I am rather confused as to what I should in order to get the values provided by the dictionary. Thus, it would be greatly appreciated if anyone could help me understand how I gain the values of the dictionary.

There is a bug. The stub (default generated code) is almost empty. Weā€™ll look into it.

Problem fixed, thanks for the report. You might need to reset your code to get the proper default code.

1 Like

There seems to be a bug in my code. By right my output should be a word that scores 12 points and I know its wrong. But instead, I donā€™t even get an output all I get is undefined. Here is my code:

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
let arr = []
let arr2 = []
var N = parseInt(readline());
for (var i = 0; i < N; i++) {
    var W = readline();
    arr.push(W)
}
var LETTERS = readline();
let arr3 = []
let y = 0
// Write an action using print()
// To debug: printErr('Debug messages...');
let values = {'a':1,'b':3,'c':3,'d':2,'e':1,'f':4,'g':2,'h':4,'i':1,'j':8,'k':5,'l':1,
'm':3,'n':1,'o':1,'p':3,'q':10,'r':1,'s':1,'t':1,'u':1,'v':4,'w':4,'x':8,'y':4,'z':10}
for(let i = 0;i<arr.length;i++){
    y = 0
    arr3 = arr[i].split('')
    for(let x = 0;x<arr3.length;x++){
        y += values[arr3[x]]
        }
        arr2.push(y)
        }
let sumIndex = arr2.reduce(function(p,n){
if(p>n){return [p]}
if(p===n){return [p,n]}
else{return [n]}
})
for(let i = 0;i<sumIndex.length;i++){
print(arr[arr2.indexOf(sumIndex[i])])
}

Please do help because I am confused as to why this is the case. Is the code wrong? And if it is, how so?

Has anybody figured this out? Iā€™m having the same problem

Wait never mind I figured it out! To anybody wondering itā€™s most likely because you forgot that you donā€™t have to use all of the letters.

1 Like

Iā€™m having an issue right now where I pass all of the test cases, but for some reason when I submit, the 2 words with different values test is supposedly wrong(says that it is hardcoding). I donā€™t know how to fix this because I am getting the correct answer, and I donā€™t know how Iā€™m hard coding. Anyone know how I could fix this

Did you ever figure this out? Iā€™m having the same problem

Hey there,

I have the same issue as Bridgetn58: all my tests passes, but when I submit the ā€œ2 words with different valuesā€ test fails and I have no clue about the reason. I tested my code with different output, more than the ones in the test, the chosen one is always the one with highest value. I made the test in PHP.
Can anyone help?

Thanks,

Iā€™ll send the validator test by PM.

1 Like

It helped me finding my error, thank you!

Thanks for your examples, I had problem with validation for the third too, it helped me to find my problem and solve it.