GlobalLogic interview question

coding solution and logic building