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