a friend of mine was asked on interview to solve the following exercise but didn\'t succed. I wanted to try it on my own but it seems to be harded than I though at first glance,