Nasdaq interview question

solve some problems in the code