patience diff algorithm