The task of a job interview at one major Swedish site

    I am a PHP-Developer, I live in Stockholm. Recently I was interviewed in one large Swedish site (more than a billion page views per month). The interview was conducted by 2 programmers from this company. At a certain point, one of them took out a piece of paper and said that they were offering me to solve a small problem (right there on paper, without a computer). And that I have 10 minutes. They asked to comment on each step in the same way.

    I will say right away that I did not solve it. At first everything seemed to be simple, and then ... So, I left the meeting not saltyly slurping. For my part, she remained unresolved.

    Why publish this? Firstly, it might be useful to someone as a good test for hired developers; secondly, someone, if he encounters something similar, will already be full of knowledge; thirdly, can someone put the right decision in the comments?

    Below is the task itself. I leave everything in the original as it was.

    PHP assignment
    Write a function, read_conf ($ filename), that converts the configuration below into a multidimensional array.

    The configuration is divided up in rows and each row is divided up by key and value. The key can be multidimensional, and can be from 1 ... N, in the example below we only have 4 levels, but the solution should be able to work even when adding another row with more key levels: eg. session.save.db.master.host = 10.0.0.1

    === config.txt ===
    id = www
    session.timeout = 120
    session.server.0.host = 127.0.0.1
    session.server.0.port = 1111
    session.server.0.id = session1
    session.server.1.host = 127.0.0.1
    session.server.1.port = 1111
    session.server.1.id = session2
    image.width = 640
    image.height = 480
    image.watermark.small = wsmall.png
    image.watermark.normal = wnormal.png

    === code ===
    $ res = read_conf (" config.txt ");
    var_dump ($ res);
    ?>

    === output ===
    array(3) {
    ["id"]=>strong(3) "www"
    ["session"]=>array(2) {
    ["timeout"]=>string(3) "120"
    ["server"]=>array(2) {
    [0]=>
    array(3) {
    ["host"]=>
    string(9) "127.0.0.1"
    ["post"]=>
    string(4) "1111"
    ["id"]=>
    string(8) "session1"
    }
    [1]=>
    array(3) {
    ["host"]=>
    string(9) "127.0.0.1"
    ["port"]=>
    string(4) "1111"
    ["id"]=>
    string(8) "session2"
    }
    }
    }
    ["image"]=>
    array(3) {
    ["width"]=>
    string(3) "640"
    ["height"]=>
    string(3) "480"
    ["watermark"]=>
    array(2) {
    ["small"]=>
    string(10) "wsmall.png"
    ["normal"]=>
    string(11) "wnormal.png"
    }
    }
    }

    Also popular now: