algorithm and solution for the interview