Implementation of coding problem given by C42