implementation of some algorithm interview question