Haskell, 173 166 bytes, 159 bytes in GHCi
Here is the normal version:
import Data.List
t=length
j[_]=0
j l=y[t f|a<f|f<-Data.Listfst.permutations[0span(>0)<$>permutations[0..t l-1],let f=takeWhile(/=0)a,u<-f,u==t l-1,all(\(a,b)->abs(b-a)<=l!!a)$zip(0:f)$f++[0]]
y[]=0-1
y l=minimum l+1
Here is the GHCi answer (put the line one at a time):
t=length
y[]=0-1;y l=minimum l+1
j[_]=0;j l=y[t f|f<-fst.span(>0)<$>Data.List.permutations[0..t l-1],u<-f,u==t l-1,all(\(a,b)->abs(b-a)<=l!!a)$zip(0:f)$f++[0]]
Just a bruteforce. Generate the possible answer. (i.e. permutation of [0..n-1] with zero and following element dropped. Then check if the answer is correct. Get the minimum length and add by one. (Since the leading and trailing zeroes is delete).
How to use: j[3,4,0,0,6]
-> 3
It turns out that I don't have to import Data.List if I just want to use 1 function