Thank you so much!! This is the answer I was looking for!! Since creating and searching arrays is slow, I think the validation step counts how many arrays/lists you have and times you out if you added any.
For anyone else with the same issue:
I used C#, but the conclusion should be similar in other languages. My problem was that I created an extra array to split the file type by the last “.” just like the example did with " " (where it splits the 3rd input into input[0] and input [1] for the file extension and MIME type). There is no need for that extra array. I needed to figure out how to use a substring on the file name to access the last letters after the last “.” instead.
One reason might be that you created an extra array/list. Since creating and searching these are so slow, I think the validation step counts how many arrays/lists you have and times you out if you added any.
The conclusion should be similar in all languages, but I used C#. My problem was that I created an extra array to split the file type by the last “.” just like the example did with " " (where it splits the 3rd input into input[0] and input [1] for the file extension and MIME type). There is no need for that extra array. I needed to figure out how to use a different method for accessing the same info (in C# I used a substring on the file name to access the last letters after the last “.” instead).
You created an extra array. Since creating and searching these are so slow, I think the validation step counts how many arrays/lists you have and times you out if you added any.
The conclusion should be similar in all languages, but I used C#. My problem was that I created an extra array to split the file type by the last “.” just like the example did with " " (where it splits the 3rd input into input[0] and input [1] for the file extension and MIME type). There is no need for that extra array. I needed to figure out how to use a different method for accessing the same info (in C# I used a substring on the file name to access the last letters after the last “.” instead).
UNKNOWN is the good answer in both cases, the error must be on a previous line.
Note that your answer is checked line by line, and that the verification stop on the first encountered error.
Btw you can check the tests content directly (which is useful for the large ones that can’t be displayed fully on the console) by clicking on this button:
The online test outputs only the first file type correct and the rest is all “UNKNOWN”.
Weirdly enough, aside for the first file, for all the other files the map find method doesn’t find the key because the Comp operator is never called (I tried to put some cout inside the method).
So far I have done this in C++, C#, and now C. For C++ and C#, they have maps/dictionaries which makes things easier. Since C doesn’t, I had to create 4 separate arrays based on the ASCII value for the first letter in the extension. My 4 arrays ranges were a2g, h2m, n2p, and q2z. The thought process is that by having one massive array it will time out going through the loops but by splitting into 4 sections even if the extension started with ‘Z’ it will only need to do 4 comparisons and then the chances of finding the extension greatly increase over having one array.
However, if anyone knows a better way to do it in C I am more than happy to hear how you did it.
Last test is not very cool because it add a new case which are “file.yes.pdf”. It’s pretty boring to have an error in this case because it’s flooded by 9998 other strings.
Add a test with “file.yes.pdf” before the last one could make this exercise less frustrating
I wrote my own functions to create and manage a hash table. I did copy the algorithm for the hash value from a website, see below, but made the rest up as I went along.
Only problem is I’m getting a miss-match on the large data set at record 9998. The MIME it’s complaining about has 669 extensions leading to it, there are 382 files with one of those types and it’s not the record it’s stopping on. Can’t get all the debug, can’t automate running it to step through the files. Ahh well, that’s tomorrows problem.
Does the console state your code times out, without any other error messages? What data structure do you use in your code, and how is it structured (e.g. does it always loop through all possibilities, or does it break whenever it finds a match)? It is better if you can briefly describe your code so that we may advise more specifically.
thx for your reply.
I use a loop that verify for each data wich extension it is.
it loop trough all possibilities and put the unknown if none is the one.
Hello cedric.c1. Could you answer the remaining questions too? That is,
Does the console state your code times out, without any other error messages?
What data structure does your code use?
Does your code break out of the loop when it finds a match?
Yes the codes time out at 3500 something try.
No others error messages .
Tried with the break when the good value is found same issue but i go up to 5000 now.
Sorry if i’m not clear enough can i send my code to you to go faster ?