Call the array `A`

*good* if it is monotone increasing.

If there is more than one index for which `A[i] > A[i+1]`

, then more than one element of the array must be changed for `A`

to be good. If there is no index for which `A[i] > A[i+1]`

, then the array is already good.

Otherwise, let `p`

be the problem index for which `A[p] > A[p+1]`

. There are a few cases.

- If
`p = 0`

, then we could make the array good by setting`A[p] = A[p+1]`

. - If
`p = len(A) - 2`

, then we could make the array good by setting`A[p+1] = A[p]`

. - Otherwise,
`A[p-1], A[p], A[p+1], A[p+2]`

all exist, and:- We could change
`A[p]`

to be between`A[p-1]`

and`A[p+1]`

if possible, or; - We could change
`A[p+1]`

to be between`A[p]`

and`A[p+2]`

if possible.

- We could change

```
def checkPossibility(self, A):
p = None
for i in xrange(len(A) - 1):
if A[i] > A[i+1]:
if p is not None:
return False
p = i
return (p is None or p == 0 or p == len(A)-2 or
A[p-1] <= A[p+1] or A[p] <= A[p+2])
```