g | x | w | all
Bytes Lang Time Link
114APLNARS241227T113628ZRosario
020Haskell + hgl241215T233450ZWheat Wi
116Wolfram Language Mathematica241215T134058ZIntroduc
011Jelly241213T194404ZJonathan
013Vyxal241214T025506Zemanresu
035Uiua241213T222115ZJoao-3
018Jelly241213T054154ZUnrelate
092JavaScript Node.js241213T033843Zl4m2
087Python 2241212T120359Ztsh
150R241213T024108ZEonema
050Charcoal241212T171908ZNeil
101JavaScript ES6241212T170125ZArnauld
01505AB1E241212T084928ZKevin Cr

APL(NARS), 114 chars

r←w c i;a;b
r←1⋄b←a←2⋄→3
a←1+b←¯1
→0×⍳(≢w)<i+1⋄→a×⍳0<b×-/w[i,i+1]⋄i+←1⋄r+←1⋄→3

{i←a⍳m←⌈/a←{k c⍵}¨⍳≢k←⍵⋄⍵[i..i+m-1]}

-- 11+12+8+44+ 3+ 36= 114

it is based from 2 functions, the "c" function that return the max lenght of bitonic array start index i from array w. One un-named function that apply the function "c" to each element of array ⍵, it finds one array of lenghts, it finds the max bitonic lenght, return the max lenght sublist that is bitonic. This below is the function "c" with line numbers, useful for see where "→" goes... "→0" means exit from the function.

   r←w c i;a;b
1: r←1⋄b←a←2⋄→3
2: a←1+b←¯1
3: →0×⍳(≢w)<i+1⋄→a×⍳0<b×-/w[i,i+1]⋄i+←1⋄r+←1⋄→3

the test it seems goes well:

  f←{i←a⍳m←⌈/a←{k c⍵}¨⍳≢k←⍵⋄⍵[i..i+m-1]}
  f , 1
1 
  f (¯1,2,1,3,1,4,1,5,1)
¯1 2 1 
  f (3,2,3,4,5,3,2,1,5,2,3)
2 3 4 5 3 2 1 
  f (1,2,3,2,3,4,5,3,2,1,5,2,3)
2 3 4 5 3 2 1 
  f 1,2,5,6,3,2,1,0,6,3,2,1,0
1 2 5 6 3 2 1 0 
  f 3,3,2,2,3,3,4,4,4,5,5,5,5,3,3,2,2,1,1,5,5,2,3
2 2 3 3 4 4 4 5 5 5 5 3 3 2 2 1 1 
  f 1,2,3,4,5
1 2 3 4 5 
  f 5,4,3,2,1
5 4 3 2 1 

Haskell + hgl, 20 bytes

xBL<cSt(mnI<pac<nbc)

Attempt This Online!

Explanation

Parsers, 27 bytes

ggL$Rv$ah'$h'@~mnI<>h'@~mnD

Attempt This Online!

I wanted to do this with parsers to see how bad it would be. It's bad. It's not that bad.

Explanation

Reflection

I am a little disappointed. I am also kind of annoyed by the challenge. The arbitrary choice to require the first such answer in a tie irritates me, since it feels like it just stifles creativity.

However I can still learn from this.

Wolfram Language (Mathematica), 116 bytes

First@MaximalBy[#,Length]&@SequenceCases[#,{x___,y___,z__}/;OrderedQ[{x,y}]&&OrderedQ[Reverse[{z}]],Overlaps->True]&

Try it online!

Jelly,  15 14 13  11 bytes

-1 thanks to Unrelated String (sublists reversed sorted by length, ẆṚLÞ -> sublists of reverse, each reversed, ṚẆU).

ṚẆUtṂ$ÐLÐḟṪ

A monadic Link that accepts a list of integers and yields the first, longest bitonic sublist.

Try it online!

How?

ṚẆUtṂ$ÐLÐḟṪ - Link: list of integers, I   e.g. [3,1,2]
Ṛ           - reverse {I}                      [2,1,3]
 Ẇ          - all non-empty sublists of {that} [[2],[1],[3],[2,1],[1,3],[2,1,3]]
  U         - reverse each of {those}          [[2],[1],[3],[1,2],[3,1],[3,1,2]]
              (-> all sublists of I ordered by length then right to left)
        Ðḟ  - discard those Sublists for which:
      ÐL    -   repeat until results are no longer unique under:
     $      -     last two links as a monad - f(Sublist):
    Ṃ       -       minimum {Sublist}
   t        -       remove {that} from both ends of {Sublist}
                (only a bitonic sublist results in an empty list, and
                 non-empty lists are truthy) 
          Ṫ - tail

Vyxal, 13 bytes

ÞSṘÞṡ'¯ꜝ±ÞṘ;t

Try it Online! Port of Jonathan Allan's Jelly answer feat. Why Does Vyxal Have A "Is Reverse Sorted" Builtin?

ÞS            # Sublists
  Ṙ           # Reversed
   Þṡ         # And sorted by length
     '     ;  # Keep those where
        ±     # Signs of
      ¯       # Consecutive differences
       ꜝ      # Excluding zeroes
         ÞṘ   # Are sorted in reverse?
            t # Take the last i.e. longest and earliest one

Uiua, 35 bytes(SBCS)

⇌⊡⊢⍖⊸⍚⧻▽⊸≡◇(<2/+⧈≠▽⊸⌵±⧈-)/◇⊂⧅(□⧅□⇌)

Try it in the pad!

Takes in an array of numbers, outputs the longest bitonic subarray, □ boxed, because unboxing it with ◇ content would be one character longer.

Jelly, 19 18 bytes

IṠo@\IŻ=2ÄkµÐƤẈÞṪḢ

Try it online!

-1 by remembering that by the time I need to bandaid the sort order I'm just in truthiness land

Probably loses to something that brute forces over all sublists directly, but porting Kevin Cruijssen's 05ab1e solution doesn't strike me as viable due to a number of substantial differences in the builtin set.

           µÐƤ        For every suffix of the input:
 Ṡ                    Take the signs of
I                     the forward deltas,
    \                 scan by
  o@                  right ? right : left,
     I                take the forward deltas of that,
      Ż               prepend 0,
          k           and partition the original suffix after the positions of
       =2             twos in that--i.e.,
IṠ    Ż               before delta signs which
     I =2             jump from -1 to 1
  o@\                 compared to the last nonzero delta sign.
         Äk           (Also partition everything after that into singletons.)
               Þ      Sort lexicographically ascending by
              Ẉ       the lengths of each partition,
                ṪḢ    and take the first partition from the last element.

JavaScript (Node.js), 92 bytes

x=>(g=i=>(e=x.slice(i,n+i||1/0)).some(t=u=c=>t?u>(u=c)&&++t:u<(u=c))?g(n+i?i+1:!--n):e)(n=0)

Try it online!

Python 2, 87 bytes

def f(a,*p):i=iter(map(cmp,a[1:],a));return a*((-1in i)>(1in i))or f(*p+(a[:-1],a[1:]))

Try it online!

Notice that this answer is in Python 2 instead of Python 3. They have several differences:

R, 150 bytes

\(x)`if`(length(x)-1,{y=rle(x)
p=rle(cumsum(c(T,diff(diff(y$v)>0))>0))
q=which.max(p$l)
r=cumsum(p$l)[q]+1
inverse.rle(lapply(y,`[`,(r-p$l[q]):r))},x)

Attempt This Online!

Two things I couldn't figure out (and would love if someone has ideas for):

Commented:

\(x) `if`( # if statement to handle case where length(x) == 1
  length(x)-1, # F if length 1, T otherwise
  {
    # run-length encoding to avoid problems with repeated values
    y = rle(x) 
    # get lengths of bitonic stretches
    p = rle(
      # give a unique number to each potential bitonic stretch
      # i.e., increment group number whenever it starts increasing
      cumsum(c(T, diff(
        diff(y$v) > 0
      )) > 0)
    )
    # index of longest bitonic stretch in p
    q = which.max(p$l)
    # index of end of longest bitonic stretch in y
    r = cumsum(p$l)[q] + 1
    # inverse of run-length encoding
    inverse.rle(
      # lapply is needed to subset both the $length and $values of y
      lapply(y, `[`, 
        # indices of longest bitonic subarray in y
        (r-p$l[q]):r
      )
    )
  },
  x
)

Charcoal, 50 bytes

≔⟦⟧θFA«⊞θιW№⭆EΦθμ⁻λ§θμ⎇λ‹λ⁰ω10≔Φθμθ¿›LθLυ≔⮌⮌θυ»⭆¹υ

Try it online! Link is to verbose version of code. Explanation:

≔⟦⟧θFA«

Start looping over the input values.

⊞θι

Collect the next value.

W№⭆EΦθμ⁻λ§θμ⎇λ‹λ⁰ω10

While the subarray contains a decreasing pair followed by an increasing pair...

≔Φθμθ

... remove the first element from the subarray.

¿›LθLυ

If this subarray sets a new length record, then...

≔⮌⮌θυ

... remember a clone of the subarray.

»⭆¹υ

Pretty-print the first longest valid subarray.

Incorrect 55 byte version which allows both decreasing and increasing as well as increasing and decreasing, because I misread the question:

≔⟦⟧θFA«⊞θιW⬤⪪I⊕φ²№⭆EΦθξ⁻ν§θξ⎇ν‹ν⁰ωλ≔Φθμθ¿›LθLυ≔⮌⮌θυ»⭆¹υ

Try it online! Link is to verbose version of code. Explanation: As above but allows either an increasing pair followed by a decreasing pair or a decreasing pair followed by an increasing pair but not both.

JavaScript (ES6), 101 bytes

a=>(g=n=>a.some((m,i)=>!(b=a.slice(i,i+n)).some(p=v=>(m=p<m?m:p)>p&p<(p=v)))/b[--n]?b:g(n))(a.length)

Try it online!

05AB1E, 15 bytes

ŒRéR.ΔÔ¬š¥dÔJR!

(Don't) try it online (it's too slow to even handle the example test case).
Verify all test cases with a small addition of 3.£ to speed things up substantially.

Explanation:

Œ               # Get all sub-lists of the (implicit) input-list
 R              # Reverse this list of sub-lists †
  é             # Then sort it from shortest to longest
   R            # Reverse that again so it's from longest to shortest
    .Δ          # Pop and find the first/longest sub-list that's truthy for:
      Ô         #  Connected-uniquify the sub-lists ††
       ¬š       #  Prepend its first item
                #  (edge case for inputs of length 1)
         ¥      #  Pop and get the forward-differences
          d     #  Check for each if they're non-negative (>=0)
           Ô    #  Connected-uniquify this list of checks
            J   #  Join them together
             R  #  Reverse it
              ! #  Factorial †††
                #  (only 1 is truthy in 05AB1E, so this will only be truthy if the
                #  `ÔJR` was "0", "1", or "01" ††††, and falsey otherwise)