contains algorithm for sample problem