some MS and google interview problem