mb logic of the algo is incorrect ? check the logic.