Solution to the problem to the given coding task