Scrabble puzzle discussion


#126

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.


#127

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

}

`


#128

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.


#129

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


#130

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


#133

There are not enough letters in player's hand for "restaurateur". Every letter may be used once, as intro says.


#134

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.


#135

You're right. We'll look into it.


#136

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.


#137

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


#138

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


#139

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?


#140

Has anybody figured this out? I’m having the same problem


#141

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.


#142

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


#143

Did you ever figure this out? I’m having the same problem