MIME Type puzzle discussion

I realize that this case consideration is only to the MIME types array (or list, dictionary, etc), this value must to be saved with no modifications, and the extensions array must be always converted to lower case.

In my solution the extensions array and the MIME types array are parallel arrays.

When is time to validate the file names, iterating the extensions array with a for loop I check if the extension in the file name (converted to lower case) is equal to one item of the extensions array, if true, the item from the MIME types array that corresponds to the iteration (parallel arrays) is added to the response.

And all the tests passed.

In other words, it doesn’t matter if in the input there are file names with rare extensions like .cSs the output must to find the correct extension and return the MIME type exactly like was previously defined (e.g, “.tif” must to show “image/TIFF”, “.cSs” must to show “text/css”).

I am not a native of the English language, I hope this helps.

Hi Guys,
I did my program with Python and like most of people, all my tests has been ok except two tests. (5th Detection of same prefix extensions and 10th Large dataset.)
Here is my code (I’m a beginner please be kind with me :sweat_smile:):
[Mod edit: avoid posting codes on the forum]
I spend lot of times but don’t find any solutions.
Can someone help me please? (sorry for my English)

Try using a dictionary. It should work faster than a list in this puzzle.

it works ! thanks

Can someone help me? It passes all tests except “Large dataset”. How should I optimize this?

const N = parseInt(readline()); // Number of elements which make up the association table.
const Q = parseInt(readline()); // Number Q of file names to be analyzed.
var ext = [];
var mt = [];
for (let i = 0; i < N; i++) {
var inputs = readline().split(’ ');
const EXT = inputs[0]; // file extension
const MT = inputs[1]; // MIME type.
ext[i] = EXT;
mt[i] = MT;
}
for (let i = 0; i < Q; i++) {
var a = 0;
const FNAME = readline(); // One file name per line.
for(let j = 0; j < N; j++){
if(FNAME.lastIndexOf(“.”) >= 0 && FNAME.slice(FNAME.lastIndexOf(“.”)+1, FNAME.length).toUpperCase() == ext[j].toUpperCase()){
console.log(mt[j]);
a++;
break;
}
}
if(a == 0){
console.log(“UNKNOWN”);
}
}

Try using a dictionary instead of checking the extensions one by one.

Hello

I’m blocked for the large dataset in C++.
I used the map and the break (to stop when the extension is found), but I keep getting the message that the process execution time has been exceeded.

Is there any more tips ?

Do you iterate through the keys one by one to look for a match? If so, that’s probably too slow and also unnecessary.

It is just bugged.
It won’t accept any answer, even if it is supposed to be the good one

Probably your code is bugged. If you want, you may send me your code in private message and I can have a look later today.

what do you do then??

See my answer here.

To me, as a beginner in C#, this puzzle is very hard and complex.
I cannot even solve the second test.
I don’t understand why my defined array with stored values cannot be reversed.
Is there even needed array reversing?
Definitely not easy puzzle for me.
Is there super easy ones?

There is a bug in COC C#, because Test2 fails even on outputting “UNKNOWN” with Console.WriteLine().
Standard Output Stream shows UNKNOWN, but no matter what:

Found: Nothing
Expected: UNKNOWN

my code below:

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

class Solution
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine()); // Number of elements which make up the association table.
        int Q = int.Parse(Console.ReadLine()); // Number Q of file names to be analyzed.

        string[] arr = new string[N];

        for (int i = 0; i < N; i++)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            string EXT = inputs[0]; // file extension
            string MT = inputs[1]; // MIME type.

            arr[arr.GetLength(0)-i-1] = MT;
        }
        for (int i = 0; i < Q; i++)
        {
            string FNAME = Console.ReadLine(); // One file name per line.            
        }

        bool found = false;

        foreach(var item in arr)
        {
            if(item.Contains("gif") || item.Contains("png") || item.Contains("html"))
            {
                Console.WriteLine($"{item}");
                found = true;
            }
            else
            {
                found = false;
            }
        }

        if(!found)
        {
            Console.WriteLine("UNKNOWN");
        }
    }
}

There’s a bug in your code. You’re reading file names and then disregarding them right away.

If this puzzle proves too difficult for you, you may want to learn and brush up your C# knowledge using other websites first. CodinGame is intended for those with basic knowledge in a programming language.

You are right about having bug in my code.
The bug I found in ‘else’ statement where I missed adding output Console.WriteLine(“UNKNOWN”).
Not sure if bug accounts not in disregarding file names. I haven’t made there yet.
But thanks anyway for mentioning!

You’re welcome.

If you have further questions regarding your code, you may share it with me via private message. It’s better not to post codes in public in this forum.

Ok, got it!:slight_smile:

ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
add this to the beginning of the main function)

Hi, I think there is something broken in the tests at least for c++.
My old c++ solution that already passed two years ago, times out in the last ide validator.
I tried several (valid) c++ solutions from other users here and they also time out.
In fact, I couldn’t find a single c++ solution that was published on codingame for this puzzle that passed in the ide.
The Java version of my program (which is identical in every aspect) passes all tests.