Lets say we have integer array $A$ with size $n$ and $B$ with size $k$. Items in $B$ are unique.

I want to come up with a dynamic programming algorithm that finds indices $j'<j”$ such that all elements of $B$ belong to $A[j’:j”]$. I want to minimize the difference between $j”$ and $j’$. At the end, I want to return $j’$ and $j”$ if such pair exists.

For example, $A = [1, 2, 9, 6, 7, 8, 1, 0, 0, 6]$ and $B = [1, 8, 6]$ then $Bsubseteq{A[1:6]}$ and $Bsubseteq{A[4:7]}$. Since $7-4<6-1$, we return $j’=4, j”=7$.

Please help!