Algorithmic task for Scalac interview process