MIME Type puzzle discussion

You can still do manual checks with strlen before adding a value to your array. And same applies about type, with the is_string function if you really need it.

make sure you use toLowerCase(), and store them in the beginning as toLowerCase, as if you do it in the for loop, you’re going to slow the program down, i.e fail.

Where can I see the test for checking Limit size in extensions? I print “UNKNOWN” if length ext file > 10, but this not work. Test fail. All other test good.

1 Like

Thank you so much! This sent me searching down the right path.

efficient algorythm? i was solving this puzzle in pascal, so i used ExtractFileExt(FNAME) from sysutils and AnsiIndexText(FNAME, EXT) from strutils
last procedure searches in array of strings, and my solution passed 100% of tests instantly
i didn’t even bother myself with additional validation tests on submit, except those that are available in online ide window

I think this puzzle couldn’t be solved in Matlab (no hash table…). I like the reference to “Les inconnus” in the last test :slight_smile: , I first though CodinGame was American.

Hi,I have questions :
1- in C , is it better to use linked list with hash table or arrays in this exercise ?Because i have issues with the last test
2-I don’t understand why my code doesn’t pass “Limit size in extensions”

Hi @Corneille_K,

I’m using a map for the mime types and a list of strings to check if a map key exists.

@ronlobo , is it possible to do it in C ? i’m beginning the C++ and i’ve vaguely heard about map , i’m not accustomed to that

@Corneille_K, pretty sure you can solve it in all available languages, my C time is a while ago, but an enum might come in handy to map the mime types.

I wrote my code in Java and used a HashMap for the key/value pair, but the last test fails LargeDataset containing about 9999 records or more fails at some point and I just cant figure out where is there anyway this can be debugged, please render your suggestions

I did my 100% in C++ with plain old std::map :slight_smile: And with manual but correct back-dot-find in filenames.

I have made my solution in C++, it passes all the test cases successfully, but when I submit my solution, I got 90% with Consideration of the case (upper or lower) (100 pts) not being validated.

How could I know where I misdid in my solution ? it’s weird that the test cases don’t coverage all the test conditions but the validation test do.

I had the same. I didn’t see any problem with logic. The failed output this:
Fail
Found: “U”
Expected: “i”
Then by dividing number of files in half every time and replacing Q in the for cycle, got problematic entry: “.ico” at i=20. And it was problem with the code borrowed from web as I had:
int dotPosition= FNAME.lastIndexOf(’.’);
if (dotPosition >0 ) {
but what needed to be there is:
if (dotPosition != -1 ) {

I had noticed that the MIME types should be left alone, i.e do not reset them all to lower or upper case.

1 Like

Thanks…

This solved it for me!!! Thanks Heaps.

Also solved “limit size in extensions” at the same time! Kept thinking it was because extension was too long, but actually it was too short!

  • javascript

My language is C#. Indeed (and obviously) using a Dictionary (map) instead of Lists will get you to pass the 5th test case (the large dataset). Also you might want to add the extensions (not needed for MIME types) in UPPER or lower in the dictionary so that you can use the ContainsKey(key) method later, when you’re searching for your file extension, where key would be your string file extension which you will use as the method parameter as ext.ToUpper() or .ToLower (in case your file has an extension) and not worry about UPPER or lower case letters at all.

3 Likes

Thanks to all for the tip on using the dictionary datatype. That was all I needed to finish this bad boy up. Thanks!

It is possible to pass all the tests with C, without using a map.
Someone else suggested that you should break out of the for loop that searches the array of extensions. This helps a lot.
Also, it is worth converting all the given extensions to lower case while reading them in.