MIME Type puzzle discussion

I keep getting a segmentation fault during the inputs for the large dataset using C. It works just fine for the rest of them, just not for the last test! Any advice?

1 Like

what is wrong with array of strings? i really don’t understand

I did it with arrays of strings and without maps 100%, but i had to deal with problems like handling null entries and breaking out of the for loop.

I think maps are more efficient.

it does not resolve file ext for all cases, or it returns an ext where there is none.

1 Like

Hola, gente. He resuelto el problema en Limit size in extensions.

Supongamos una extensiĂłn mp3

Si tenemos un archivo file.m debe ser UNKNOWN
Si tenemos un archivo file.mp debe ser UNKNOWN
Si tenemos un archivo file.mp3 debe ser audio/mp3

1 Like

Hey guys, can anybody help me out? I’m using Java for this and my program fails to pass the large dataset. At first I was using arrays and linear search, it took too long. Then I tried arrays and binary search. Even that didn’t work in time, so I learnt about hash tables and used the Hashtable and HashMap classes. That too didn’t help… is there any way I could do this without resorting to another programming language? (I can see some forum entries where people have done it using C) Thanks!

I was able to complete it in JavaScript with a couple arrays and no sorting… seems like Java would be able to do the same, but maybe I’m wrong. It took some tweaking, but I was able to get it to pass the large dataset. Here are a few things I did:

  • Stored my extensions / mime types in separate arrays. Get hit on extension, use same index to mime type.
  • Save the extension list as uppercase on load, saves uppercase call on compare when checking against file name extension.
  • Exit extension checking loop when you find result (i.e. break).

I wish you good luck.

Phew!
I was able to do this and get 100% using C Language.
I had to create my own version of Hashtable since it doesn’t exits in C Language.
After a couple of tries, I did it!

If you need any help on how I did it, just ask me.
I know it is not the perfect solution but I would love to talk about it and see how I can improve it.

Hello, i write my program in c++ and the output is the same like the out.txt in Large database case. Here the last 5 lines from my program and the fail:

video/x-ms-wmv
application/octet-stream
application/vnd.ms-excel
application/zip
UNKNOWN
UNKNOWN

Fail
Found: “U”
Expected: “i”

Is this a bug? The last file is iLowerCaseAndUpperCaseLetters. and the right answer is UNKNOWN.

Hey,

These type of puzzle let you write you full output and then they compare with the expected output.
The fail explanation is not about your last line.

There must be a line somewhere that is waiting for image/… and you write UNKNOWN, or a line you do not write. Try to check it out.
If you cannot find the problem in your code, you may count the number of UNKNOWN you have, and do the same with the expected output, and compare the result. It should tell you if there really is problem with your code or not.

Hello,

I am failing at the Large dataset test in C++ and can’t figure what I could improve.
I am using map<string, string> this way to find extension :

if (map.count(extension) > 0)
return map.at(extension);
return “UNKNOWN”;

It appears to be too slow. What could be a faster solution using C++ ?

im having the same issue, i don’t know the line where it failed. it is impossible to know since it has 9999 lines. they should provide the line where the the failing occured so we could debug

I’ve found out that this problem existed because I wasn’t allowing files like “.gif” and it seems i have to. Doesn’t make much sense though…

Hi All!

a similar issue occurred to me. My problem was related to the extraction of the extension (and the filename): I chose regular expressions and the first version with the similar problem only accepted filenames with at least one alphanumeric character. After accepting “empty” filename, e.g. for “.ico” my solution runs smoothly.

Good luck! :wink:

Can you explain how you solve this game in C#:slight_smile: Because my latest version is working 3times faster that 1st one, and still is 2slow:(

in c#? easy:
to make an extension from any given filename i use String.lastIndexOf(’.’) method, then Substring
then, to find given extension in array of known extensions i use Array.IndexOf(array, ext) method
so i have index of corresponding mime type, because EXT and MT arrays are parallel

I solved it already, like 3 hours ago

[EDIT: NO FULL CODE]

One part of the test coverage was only done in the large dataset test in IDE.
Test 3 in IDE has been modified to cover that part.

You might need to submit to code once to see the difference.

Hey,

here is something tricky I think :

on the 5th test, you have a file name which is “.gif”, I was thinking that a filename was like “xxx.gif” with at least an “x”, it’s rare but it exists without “x”, I’m ok with it, but maybe this test can be made on the 3rd test and not on the 5th (which is very long, so it’s hard to find where it isn’t working)

I hope I have been clear :slight_smile:

Simon

Posted at the same time :slight_smile:

That’s exactly what we just modified, and indeed we added this case in the third test :wink: