Frankly i've been programming for a few years i would not be able to solve the problem in 20 mins. Maybe in 3/4 hours but 20 mins no way. I could come with an idea to solve it though.
But that's a very good exercice.
> I am first year maths student at Uni Warsaw
then Math is your major discipline. Please write down how you would express the solution in a pure mathematical form.