[Question]
  [
Take this array:
```
[1, 2, 6, 4, 4, 1, 0, 0, 2, 0, 4, 1, 4, 2, 4, 8, 1, 2, 4]
```
There are quite a few places where `[1, ..., 2, ..., 4]` appears, where `...` is any number of items. These include `[1, 2, 6, 4]`, `[1, 0, 0, 2, 0, 4]`, `[1, 0, 0, 2, 0, 4, 1, 4]`, and `[1, 2, 4]`. The shortest of these is simply `[1, 2, 4]`.
**Task:**
Given two arrays of any (reasonable) data type you choose, find the shortest slice of the first which contains all items in the second in order. There is guaranteed to be at least one such slice.
If there are multiple, you may return any one of them. Neither array will be empty. Duplicate items may appear in the second list.
**Test cases:**
```
[1, 2]                        [1, 2]        ->  [1, 2]
[2, 1, 3, 2]                  [1, 2]        ->  [1, 3, 2]
[1, 2, 4, 8]                  [1, 4, 8]     ->  [1, 2, 4, 8]
[0, 1, 1, 0, 0, 1, 1, 1, 0]   [0, 1, 0]     ->  [0, 1, 1, 0]
[1, 5, 3, 7, 1, 3, 3, 5, 7]   [1, 3, 5, 7]  ->  [1, 3, 3, 5, 7]
[1, 2, 5, 1, 3, 5]            [1, 5]        ->  [1, 2, 5] OR [1, 3, 5]
```
**Other:**
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes per language wins!
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
ẆŒPi¥ƇḢ
```
[Try it online!](https://tio.run/##y0rNyan8///hrrajkwIyDy091v5wx6L/h5frH530cOcMlUdNayL//4@ONtRRMIrVUYDQIEa0kY4CkGOMIQ5i6SiY6ChYQMXBTLCUAVgLEBmAkSGcC5I1gDJhhpiCDTeH2WIMFjGHmgnjIdloClNpClVjGhsLAA "Jelly – Try It Online")
-1 byte thanks to Unrelated String
```
ẆŒPi¥ƇḢ   Main Link
      Ḣ   Find the first
Ẇ         slice (ordered by length)
     Ƈ    where
   i      the right list's index is truthy (occurs in)
 ŒP       the powerset (stable ordered)
```
1-indexing saves me a byte, thank you Dennis!
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
⟨s⊇⟩ᶠlᵒh
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w/9H8FcWPutofzV/5cNuCnIdbJ2X8/x8dHW2oo2AUq6MAoUGMaCMdBSDHGEMcxNJRMNFRsICKg5lgKQOwFiAyACNDOBckawBlwgwxBRtuDrPFGCxiDjUTxkOy0RSm0hSqxjQ2NhYA "Brachylog – Try It Online")
```
⟨  ⟩ᶠ       Find every
 s          substring of the first input
  ⊇         containing the second input as a substring.
     lᵒ     Sort by length
       h    and take the first.
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
◄Lfo€⁰ṖQ
```
[Try it online!](https://tio.run/##yygtzv7//9H0Fp@0/EdNax41bni4c1rg////ow11jGL/RxvpGOoYA1kA "Husk – Try It Online")
yes another carriage in the 8-byte golflang answer train.
[Answer]
# [J](http://jsoftware.com/), 64 bytes
```
]{~0({.+i.@>:@g)@>@{[:(]/:(g=.{:-{.)&>)@(#~]=/:~&.>)@,@{[:<@I.=/
```
[Try it online!](https://tio.run/##RY7BCsIwDIbvPkVQ2Fbssm6zTIIdBUEQPHmVncRNvfgAhb16TVvGaAr/n/9LyNdvMR/BEOQgQQHxLxHO99vFD25WhcP9B21PdhK2t@5BxVBRMRl0VDoUWS9ssZsHU9GcIRsZmJO9oqm82Lye7x/U0PLT0EFJ0QQ5Qi1BS2gldDLoNhZ3umWqYTBO6EQ3MU6oTpDitA4nU5SKQRURLiVXHey69gDHtDiIcWmtecyalPg/ "J – Try It Online")
Well 8-byte folks, let's *square* the byte count, shall we?
I could save bytes here by just trying every possible subset, but this approach seemed more interesting, and for most inputs is likely faster.
## the idea
Consider `1 3 5 7 f 1 5 3 7 1 3 3 5 7`:
* Create an equality table:
```
1 0 0 0 1 0 0 0 0
0 0 1 0 0 1 1 0 0
0 1 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 1
```
* Get indexes of ones:
```
┌───┬─────┬───┬───┐
│0 4│2 5 6│1 7│3 8│
└───┴─────┴───┴───┘
```
* Cartesian product:
```
┌───────┬───────┬───────┬───────┬
│0 2 1 3│0 2 1 8│0 2 7 3│0 2 7 8│ ...etc...
└───────┴───────┴───────┴───────┴
```
* Filter only elements that are ordered:
```
┌───────┬───────┬───────┬───────┬───────┐
│0 2 7 8│0 5 7 8│0 6 7 8│4 5 7 8│4 6 7 8│
└───────┴───────┴───────┴───────┴───────┘
```
* Sort by difference between first and last element:
```
┌───────┬───────┬───────┬───────┬───────┐
│4 5 7 8│4 6 7 8│0 2 7 8│0 5 7 8│0 6 7 8│
└───────┴───────┴───────┴───────┴───────┘
```
* Take first element, and construct full range between first and last:
```
 4 5 6 7 8
```
* Use those to index into the input:
```
1 3 3 5 7
```
[Answer]
# JavaScript (ES6), ~~89 87~~ 83 bytes
*Saved 4 bytes thanks to @tsh*
Expects `(haystack)(needle)`.
```
a=>b=>a.reduce((r,_,i)=>b.every(x=>j=a.indexOf(x,j)+1,j=i)/r[j-i]?a.slice(i,j):r,a)
```
[Try it online!](https://tio.run/##dZBRb4MgFIXf@yt4hOwWtZa4LMH9hCZ7bcjCFBuI0Qa7xv16R2npnKXkvnDO5cs5GHmWQ2X18bTu@lpNDZ8kL794KalV9XelMLbwCZo4kaqzsj945KXhkuquVuOuwSMY8pKB4Zokdm/WWrxLOrTaPdXOerMgyVT13dC3irb9ATd4nwHaCBQ75J9JCEoSdFVWC8YGkNPzCOkZI49hLpuAtoBe45jgzKLcxCUp9YHcpH6y@1WQYKYz0t96LBPzcYvQMfdKIa6Z7rd5tSDGC7JAYmJRkD3@tRd3H4HMxPQL "JavaScript (Node.js) – Try It Online")
### Commented
```
a =>                  // a[] = haystack
b =>                  // b[] = needle
a.reduce((r, _, i) => // for each entry at position i in a[]:
  b.every(x =>        //   for each entry x in b[]:
    j =               //     update j to:
      a.indexOf(x, j) //       the index of x in a[], starting at j
      + 1,            //       to which we add 1
    j = i             //     starting with j = i
  )                   //   end of every()
  / r[j - i]          //   test whether r[j - i] is defined
  ?                   //   if successful:
    a.slice(i, j)     //     update r[] to the current slice of a[]
  :                   //   else:
    r,                //     leave r[] unchanged
  a                   //   start with r[] = a[]
)                     // end of reduce()
```
---
# JavaScript (ES6), ~~91~~ 89 bytes
*Saved 2 bytes thanks to @tsh*
Expects `(needle)(haystack)`.
```
b=>g=(a,n)=>a.some((_,i)=>`${s=a.slice(i,i+n)}`.match(`^${b.join`,(.*,)*`}$`))?s:g(a,-~n)
```
[Try it online!](https://tio.run/##fZDNbsIwEITvfQofcvDSxfxGoEqmj1CJK3Kxk4ZgFOyqRr0gePXgOgkBFLryZcajz7PeqV/l0h/9fegb@5WVG14mfJFzqtAAXyjm7D6jdI3aKxkdHfdWodOMatSvBk6S7dUh3VL5GR0TtrPaSKSsh9CTp0gCvLu33MP6ZwNlao2zRcYKm9MNXY2QjAUJA3fqYQDIYECqwMu/jDESb0w6SC1j8gQzRTIXbZXWeFKlDjyShqHCsCZV6s8IZ3SVoia1ga5OvmuMZCaqTnEwZs2O18vb1RqzAxbf/3UI1m@I7gW9/7FsyLEoLw "JavaScript (Node.js) – Try It Online")
### How?
We turn the needle `b[]` into a regular expression:
```
RegExp(`^${b.join`,(.*,)*`}$`)
```
Example:
```
[1, 4, 8] ~> /^1,(.*,)*4,(.*,)*8$/
```
We recursively look for the smallest `n` such that there exists a slice `s[]` of `a[]` of length `n` that matches this regular expression.
[Answer]
# JavaScript (ES6), 93 bytes
```
a=>b=>a.reduce(r=>1/r[p=b.map((m,j)=>t=m-a[i]?p[j]:j?p[j-1]:i),++i-t]?a.slice(t,i):r,a,i=p=0)
```
[Try it online!](https://tio.run/##dU9LbsMgFNznFCxBwR/s0FSucI5QqVuLBUkc6bl1ijCJlNM7NjGkRKqEHjNPM8PQqasaDga0TQYNx9b0v@fv9jaexKhEvRe1Sk17vBxabETNMtNosU97pTHuaUdEbUWfqAbkTjedrLr5SpisgND1GhIrdyodfmCyWwqkMlRREFrkZNQGzhafcMMoKih6o2jjzkRzdwo3H5uNo9N8d3TGknjrBMkHyjIU@CoK98pI9kdTuMzyH2UZi1losogfMC4wr56W3OWHf7FA54TcwyXhKY4f5a7J1lct3Wa7dAgsqu23r@W5D@GLnb/05xJ9fvkULlfjHQ "JavaScript (SpiderMonkey) – Try It Online")
For inputs \$ a\left[1\dots N\right] \$ and \$ b\left[1\dots M\right] \$
Let matrix \$p\_{N\times M}\$ be
$$ p\_{i,j}=\begin{cases}
i & b\_j=a\_i \land j=1 \\
p\_{i-1,j-1} & b\_j=a\_i \land j>1 \land i>1 \\
p\_{i-1,j} & b\_j\ne a\_i \land i > 1 \\
-\infty & \text{otherwise} \\
\end{cases} $$
the minimal length of output \$L\$ is
$$ L = \min\_{i \in 1\dots N} i-p\_{i,M}+1 $$
And the output is
$$ a\left[p\_{i,M}\dots i\right] $$
where \$i\$ is the value for minimal \$L\$.
This solution works in \$ O\left(M^2\right) \$ time and \$ O\left(N\right) \$ extra memory.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 9 bytes
```
ÞS'ṗ⁰c;Þg
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=1#WyIiLCIiLCLDnlMn4bmX4oGwYzvDnmciLCIiLCJbMSwyLDUsMSwzLDVdXG5bMSw1XSJd)
```
       Þg # Shortest
ÞS        # sublist
  '   ;   # where
   ṗ      # powerset 
     c    # contains
    ⁰     # input
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Œé.ΔæX.å
```
[Try it online](https://tio.run/##yy9OTMpM/f//6KTDK/XOTTm8zFPv8NL//6MNdAyB0EAHQgNZsVxgMYNYAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWVC6P@jkw6v1Ds35fCyCL3DS//X6vyPjo421DGK1QGTsToK0dFGOoY6xqhCQIaOiY4FWAhEgwUNgOoMdQx0IDSQBZQ2ANNQPaZAY8zBhhkD2eZg3RAW3FBTsLQpWMoUIWwGtMUEargREIPYJhA36IDdAnEckI6NBQA).
**Explanation:**
```
Œ         # Get all sublists of the (implicit) input-list
 é        # Sort these sublists by smallest to largest length
  .Δ      # Find the first sublist which is truthy for:
    æ     #  Get the powerset of this sublist
     I.å  #  And check if it contains the second input-list
          # (after which this shortest found result is output implicitly)
```
[Answer]
# [Python 2](https://docs.python.org/2/), 94 bytes
Using `iter` to check if `s` is a subsequence of `b` is a trick I've first seen on [this answer](https://codegolf.stackexchange.com/a/217976/64121).
```
def f(a,b,i=0):l=len(a);s=a[i%l:][:i/l];x=iter(s);return s*all(v in x for v in b)or f(a,b,i+1)
```
[Try it online!](https://tio.run/##VY/NasMwEITveYq9BKRkof6JSbDRkwgdZCoTgZCDpBb36d3Vujn0ovmY1Q6zr5/yXGO3759ugUVYnNGrRo5BBReFlVNWVvtzGI0e/Ucw06Z8cUlkOSVXvlKEfLEhiG/wETZY1gSMsyT6y7u2ci8ulwwKtNYtdgb5JdEdttj/c0jxhg92qlavoV8tNngoEZkN67ExUMadk3riO@8e9E4ceDrwZDDGnGpVizDXttxuPAG8ko9F1N50gdx/AQ "Python 2 – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 60 bytes
```
≔Ｅ⌕Ａθ⊟η⟦¹ι⟧ζＦ⮌η«ＦζＦ⌕Ａ…θ§κ¹ι⊞υ⟦⁻Σκλλ⟧≔υζ≔⟦⟧υ»≔⌊ζε≔⊟εδＩ✂θδ⁺δ⊟ε
```
[Try it online!](https://tio.run/##PU/BioMwED3Xr8hxAlnQc08iLOyhIO1RchAzrUPT2BpTui777dmJ1Q0TknmPee9N17djN7Q2xtJ7ujg4tHf4JGdKa@GhRD3coZdSiaZQgjR/ZrnPzsMo4IhPHD0mWvxkuwWbpVjeTaH67ixWPYuwVjl9OYMvuCpRJEniwTr4HgLLH8gFD6dwgytTNl3NTrs1Vngbb22jlQjc/2ZbbHJ04@GZB5GJFU7xkSHDUD2Sm6Bq/QQnSx2mSIY3tOxr3puiTGcfY9PkHHKpfKniv2Xnlcy1jh9P@wc "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔Ｅ⌕Ａθ⊟η⟦¹ι⟧ζ
```
Get the last element of the array to match and find all of its indices in the array to search, yielding an array `[1, i]` for each position. These values relate to the length and start position of a slice of the array to search, initially only containing the last element of the array to match.
```
Ｆ⮌η«
```
Loop over the remaining elements in reverse order.
```
Ｆζ
```
Loop over the matches so far.
```
Ｆ⌕Ａ…θ§κ¹ι
```
Loop over all the positions of the next element in the prefix of the current match.
```
⊞υ⟦⁻Σκλλ⟧
```
Save the new match length and start position.
```
≔υζ≔⟦⟧υ
```
Move the working list back to the list of matches and clear the working list again.
```
»≔⌊ζε≔⊟εδ
```
Get the match with the shortest length and get its start position.
```
Ｉ✂θδ⁺δ⊟ε
```
Output the slice of that length at that position.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 34 bytes
```
1A`
,
.$*
~)`^
1G`¶Lw`
N$`
$.&
1G`
```
[Try it online!](https://tio.run/##LYwxDsIwDEV3nyOggqwqThNaKRNTF8TCjszAwMKAkNg4Vg/Qi4XvBFm2n77/9@v@fjxvUjbdRTN1sxY5KjH1bk/fnV5JZl2X00fp7JRcvzWhFOHAB44oYY8KaOMIijyx3WOukzCNKEAd/izNly0xkcel/ZFG2cjDlZAYa24Aj1narvlU9QQt/QA "Retina – Try It Online") Takes two newline-separated lists of distinctive words (i.e. no word is contained in another word) but link is to test suite that splits on semicolons for convenience. Explanation:
```
1A`
```
Delete the array to search.
```
,
.$*
```
Replace each comma with a regex for arbitrary content.
```
^
1G`¶Lw`
```
Prefix a command to delete the array to match and list all overlapping matches in the array to search.
```
~)`
```
Evaluate the result on the original input.
```
N$`
$.&
```
Sort the matches by length.
```
1G`
```
Take the first.
[Answer]
# [R](https://www.r-project.org/), ~~95~~, 94 bytes
#### Assuming `combn` always returns sorted indexes
At the moment the assumption is valid in all R versions, but is not documented; the alternative (longer) solution is reported at the bottom of the answer
* -1 byte thanks to @Dominc van Essen
```
function(v,s,`+`=length){for(x in combn(+v,+s,,F))if(all(v[x]==s)&+v[T]>+(y=x:x[+x]))T=y;v[T]}
```
[Try it online!](https://tio.run/##fVBdC4IwFH3vV1wIYpfdQDMpivXYaxC@iVBJK8EmZMki@u2mw9kH1rgPO2c7Z@fsXEpRyquKL0mmWEE5bfhGpHt1uBzxLrMz05AoiLPTTjFeEM@JloiJZNs0ZUWoIyFyHPAiDKIFZzehZzrkOkIMxG1es49Sspi5BCOEzkUfpwh9GC4AGrJXi0cEFfC6LP6IvVZf3yAYE0x/6O3R5@MNbywcE6Eax4zbQqwtHLt/t3hJ2hS@STWxdTzDTLBJYeF3C8u/dfGthY/fXfzOjzT8al2h0ArLJw "R – Try It Online")
## Unrolled code with explanation:
```
function(v,s){                  # take full vector v and the vector to search s
  r=v                           # init shortest slice r to full vector v
  for(x in combn(length(v),     # for each combination x of length(s) elements taken 
                 length(s),,F){ # from the vector of indexes 1:length(v)
                                # (we assume x is sorted ascending)
    a=v[x:x[+x]]                # get the slice between first and last index in x         
    if(all(v[x]==s) &           # if the values of the combinations == s and
       length(r) > length(a))   # the slice is shorter than r
      r=a                       # store the new slice
  }
  r                             # return the shortest slice
}
```
---
Version without assumption:
# [R](https://www.r-project.org/), 107 bytes
```
function(v,s,r=v,`+`=length){for(x in combn(+v,+s,,F)){y=sort(x);if(all(v[x]==s)&+r>+(a=v[x:x[+x]]))r=a};r}
```
[Try it online!](https://tio.run/##fVDLasMwELznKxYCZRdtwYljUhqUY6@FXo0hjolSgyuD7BqVkG93bWE5D5yIPWhGmtGMTKtkq351VuelxoYrNrLhndjJ4qCP9TedVGnQQq4hK3/2GkXDomL@IDr9yao0NVra5ArTosAmtomUFb0IsxWYyg6/21jYJCEyMj1vzLlVmOGCYUkwufjmlGAOr1uAgZz14iVDB8IpiyficNT3NxhWDG8P9P7o9vGBdxaBi9BN4GYxQuotAr@/trhIxhSRS7X2dULHrGlI4eF9C89fdYm8RUT3XaLJj3T851eHYi9s/wE "R – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 9 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
ã æÈà deV
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=4yDmyOAgZGVW&input=WzIgMSAzIDJdClsxIDJd)
```
ã æÈà deV     :Implicit input of arrays U=haystack & V=needle
ã             :Sub-arrays of U
  æ           :Get the first that returns true
   È          :When passed through the following function
    à         :  Combinations
      d       :  Any
       eV     :    Equal to V
```
[Answer]
# GForth, 241 bytes
```
: s 1 /string ;
: d 2drop ;
: o 2over ;
: h over >r begin o drop c@ scan 2>r s 2r> 2 pick 0= over 0= 2* or ?dup until nip 2nip 1+ swap r@ - r> -rot or ;
: f 2dup 2>r begin o o h dup r@ u< if 2rdrop 2>r else d then s dup 0= until d d 2r> 1+ ;
```
[Try it online!](https://tio.run/##bU9BbsMgELz3FXNuZdXgWqmSJs1XXBvbqDGgBSfPdwd8aaUiYGd3Z9hh9JLmahpz2LYjIhReYxLrJpyejhigB/GhYA/t70YKnlHgRfBlJuvYK7T@ith3DpqNCC0XaATbf6M@7wJG/Qwv@BzWgNUle4OzATpf6gXx0QXIFRWorcSnzM0DRxqhQv@a6Oki10hfP2DJkGIic8wtGppPs3E0klmcvI8b8qf4Oqed@OOE0Ek0lesWg9jdTbWY5d@aLubGP70k5/xymsU/6DNB6X0TatXsSaNL4@0dKh8C5rVSNY@qiWqg5JnWNgfVNO2BMl4ouMhbFlCW2iNL2w8 "Forth (gforth) – Try It Online")
## Formatted & commented version
also a bit ungolfed
```
: s 1 /string ;
: d 2drop ;
: o 2over ;
\ find the first match. if there is no match, return a string with the maximum length (-1)
: h ( target container -- caddr u )
    \ store the start address of the string on the return stack
    over >r
    begin
        \ remove characters from the front of the string until
        \ the string starts with the same character as
        \ the target string (or until it is empty)
        o drop c@ scan
        \ remove a character from the front of the target string
        2>r s 2r>
        \ some magic that gives -1 if the target string is empty,
        \ -2 if the container string is empty, and 0 otherwise
        2 pick 0= over 0= 2* or
        \ duplicate the top of the stack if it isn't zero
        ?dup
        \ exit the loop if the top of the stack is something other than zero
    until
    \ get rid of everything on the stack except for new address of the string
    \ if there was a match, this will be the address of the end of the match.
    nip 2nip
    \ use this and the saved start address to reconstruct the match.
    1+ swap r@ - r> -rot
    \ if we didn't get a match, use the magic from before to replace the length with -1
    or ;
: f ( target container -- caddr u )
    \ store the current shortest match on the return stack.
    \ since it is given that there will be a match in the array,
    \ we put that on the return stack first
    2dup 2>r
    begin
        \ find the first match, and compare its length to
        \ the length of the match on the return stack
        o o h dup r@ u< if
            \ if it is shorter, replace the string on the return stack with it
            2rdrop 2>r
        else
            \ otherwise, discard it
            d
        then
        \ remove a charachter from the front of the string
        s
        \ if there are no more charachters in the string, exit the loop
        dup 0=
    until
    \ get rid of everything and retrive the stored match
    d d 2r>
    \ there's an off by one error here somewhere. rather than fix it, just add one.
    1+ ;
```
```
[Answer]
# [R](https://www.r-project.org/) >= 4.1.0, 139 bytes
```
\(x,y,`~`=\(a,b)paste(a,collapse=b))(u<-combn(1:sum(x|1),2,\(z)if(grepl(y~" .* ",(v=x[z[1]:z[2]])~"  "))v,F))[order((m=lengths(u))/!!m)][1]
```
[Try it online!](https://tio.run/##PYtLCoMwFACvEl29V15booggzbaXEMFPE1vQRIwRleLVrXXhbphh@k2JTTldDR@jYaKZ8jUXpyioxK6wg9ypMk1TdFaKEhHc41qZttTAE@tamL4cKaDzW/CjoO5l18C8@ux2YT7BKKZ0SXmWLGmQZbh75iOO9ERMTf@SPUArGqnr4W3BId49r8VsHzYFFXBiEbGQWEyMHxAeJkb6x5AiihG3Hw "R – Try It Online")
A function that takes the `x` as the vector to look within and `y` as the vector to look for. Returns a length 1 list containing the shortest matching contiguous subsequence of `x`. TIO link replaces `\` with `function` since TIO is running an earlier version of R.
[Answer]
# Python 3.8, 152 bytes
The [other python answer](https://codegolf.stackexchange.com/a/226829/71357) is too good - but just leaving mine here anyway
```
from itertools import*
f=lambda a,b:min(((Y:=c[0][0]),(Z:=c[-1][0]),a[Y:Z+1],Z-Y)[::-1]for c in combinations(enumerate(a),len(b))if[*zip(*c)][1]==b)[1]
```
older uncondensed version
```
from itertools import*
def f(a,b):
    #print(*permutations(a), sep='\n')
    combis = [*combinations(enumerate(a),len(b))]
    #print(combis)
    F=[(combi[0][0],combi[-1][0]) for combi in combis if [*zip(*combi)][1]==b]
    #print(F)
    s,e = min(F, key=lambda i:i[1]-i[0])
    #print(s,e,a,a[s:e+1])
    return a[s:e+1]
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 67 bytes
```
(c=___;#1/.{c,x:Shortest[PatternSequence@@Riffle[#2,c]..],c}:>{x})&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7XyPZNj4@3lrZUF@vOlmnwio4I7@oJLW4JDogsaQktSgvOLWwNDUvOdXBISgzLS0nNVrZSCc5Vk8vVie51squuqJWU@1/QFFmXolDWnS1oY6CUa0OhIrlQhHWUTDVUQAyjIEMiBLT2tj/AA "Wolfram Language (Mathematica) – Try It Online")
No brutal force, just patterns usage
]