algorythm solution