Contain algorithm