Algorithm

Please check this