g | x | w | all
Bytes Lang Time Link
010Vyxal 3 G250724T200633Zpacman25
019BQN250722T154807Zpanadest
088Wolfram Language Mathematica240402T050242Zlesobrod
013JCram240225T234159ZArnauld
042APLNARS240227T203705ZRosario
045Haskell + hgl240226T041852ZWheat Wi
013Jelly240226T203503Zhyperneu
093R240226T065921Zpajonk
025APL Dyalog APL240226T133827ZMukundan
02405AB1E240226T091009ZKevin Cr
063Python240225T194206ZMukundan
026Charcoal240226T103246ZNeil

Vyxal 3 -G, 10 bytes

⑴⎘i\Þ⦰~m⊆Ŀ

Vyxal It Online!

this is such a janky way to do this but there is no way to check depth in vyxal 3 so we have to get creative

-2 because scan exists oops!

⑴⎘i\Þ⦰~m⊆Ŀ­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁤‏‏​⁡⁠⁡‌⁢⁢​‎‏​⁢⁠⁡‌­
⑴⎘i           # ‎⁡fixpoint collect flatten by depth
     \Þ⦰       # ‎⁢window reduce by set difference, which just gives the sub-lists for each depth as the flattened digits are in both
        ~m⊆    # ‎⁤filter by index (depth) is a subset
            Ŀ  # ‎⁢⁡length of each valid sublist
# ‎⁢⁢G flag gets maximum of that list, will give empty list for no valid answers
💎

Created with the help of Luminespire.

BQN, 19 bytes

{(⌈´𝕊¨∾≠×1∊-)⍟=𝕩-1}

BQN online REPL

This solution is similar to the Dyalog APL approach: a recursive function that runs until it reaches an atom. It operates by first subtracting one from all numbers in the array. Then, at each level of the recursion, it conditionally multiplies by the subarray's length and finds the maximum value from this process.

Wolfram Language (Mathematica), 88 bytes

Max@Reap[Do[Do[If[MemberQ[e,l],Sow@Length@e],{e,Level[#,{l}]}],{l,0,Depth@#-1}]][[2,1]]&

Try it online!

JCram, 13 bytes (SBCS)

-1 thanks to @mukundan314
-1 thanks to @tsh

A JCrammed version, as suggested by Kamila Szewczyk.

νⓅιk⑦③⍋⍁lζ⁷⊗Ⓙ

JavaScript (ES13), 60 bytes

-4 thanks to @mukundan314
-2 thanks to @tsh

Returns 0 for undefined.

f=(a,d)=>Math.max(...a.map(v=>v.at?f(v,-~d):d^v?0:a.length))

Attempt This Online!

APL(NARS), 42 chars

{d←≡⍵⋄⌈/∊{0=k←↑⍴⍵:0⋄(k×⍵∊⍨d-≡⍵),∇¨⍵[⍳k]}⍵}

test:

  f←{d←≡⍵⋄⌈/∊{0=k←↑⍴⍵:0⋄(k×⍵∊⍨d-≡⍵),∇¨⍵[⍳k]}⍵}
  f  1 2 (3 4 (2 5)) 0
4
  f 1 (2 3) (⊂,1) (2 (2 3))
2
  f 1 1 1 1
0

Haskell + hgl 45 bytes

t y x=xd 0$[l x|p y?>x]<>(t(y+1)*~|p 0)<x
t 0

Attempt This Online!

Takes input as a List (Free List Int).

Explanation

We use a pretty straightforward recursive approach to the problem. t takes a depth y and a list x, it then gets the maximum (xd 0) of:

Then our final answer is naturally t 0 to start the depth at 0.

Point-free, 55 bytes

xd 0<jn<ixm(l<<<fl<e)<uef(mm$dFe$p(-1))(fb$m$dPr$p i)<p

Attempt This Online!

Ech! This is long. I will see about fully explaining and breaking down a reflection tomorrow.

Explanation

A rough explanation is as follows:

Reflection

Let's start by pointing out the obvious, Haskell is a strongly typed programming language, and ragged lists are not very nice for strongly typed languages. That's why we have to use the weird type List (Free List Int) here. List (Free List Int) is a pretty specific type and there are not a lot of tools to deal with it, which is why half of the point-free answer is manipulating this type into another form.

That being said I'm still disappointed in this answer. The fact that the best approach (that I can find) isn't point-free, points to the fact that this is a recursion scheme that isn't well supported in the library. There are issues here, along with a couple small things to be improved.

Jelly, 13 bytes

0LȦ?»ŒḊƇ’߀ṀƲ

Try It Online!

I'm sure this could be done much better, but I am rusty. Returns 0 for undefined.

Explanation

0LȦ?»ŒḊƇ’߀ṀƲ  Main Link
  Ȧ?           If any and all (that is, no 0)
0                Return 0
 L               Else return the length
    »          Take the maximum of the above and ...
           Ṁ   The maximum of
         ߀    This link recursively applied to each of
        ’      The (vectorized) decrement of
     ŒḊƇ       This list filtered for non-zero depth

Numbers have a depth of zero, so ŒḊƇ returns all elements of the list that are themselves lists.

In place of 0LȦ?, the following also work:

R, 97 93 bytes

Edit: -3 bytes thanks to @Giuseppe.

f=\(L,d=0,l=0,`[`=sapply,`?`=max)`if`(is.list(L),?L[f,d+1,length(L)*any(L[identical,d])?l],l)

Attempt This Online!

APL (Dyalog APL), 25 bytes

{⍬≢⍴⍵:(⌈/∇¨,≢ׯ1∊⊢)⍵-1⋄0}

Returns 0 if there is no match.

Attempt This Online!

{⍬≢⍴⍵:(⌈/∇¨,≢ׯ1∊⊢)⍵-1⋄0}­⁡​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠⁠‏​⁡⁠⁡‌⁢​‎⁠⁠‎⁡⁠⁢⁡⁤‏⁠‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠⁠‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁤‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏⁠‎⁡⁠⁢⁡⁡‏⁠‎⁡⁠⁢⁡⁢‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁢⁢⁣‏⁠‏​⁡⁠⁡‌⁢⁤​‎‎⁡⁠⁢⁢⁤‏‏​⁡⁠⁡‌­
 ⍬≢⍴⍵                      # ‎⁡if argument is not a scalar
                   ⍵-1     # ‎⁢  decrement all elements by 1 (including nested elements)
       ⌈/                  # ‎⁣  maximum of
         ∇¨                # ‎⁤    recursive call on each element
           ,               # ‎⁢⁡    concatenated to
            ≢ׯ1∊⊢         # ‎⁢⁢    length * (-1 exists in argument)
                      ⋄    # ‎⁢⁣else
                       0   # ‎⁢⁤  return 0
💎

Created with the help of Luminespire.

05AB1E, 25 24 bytes

"Ð0åigˆ}<εD.ïië®.V"©.V¯à

As always, or recursive challenges aren't really 05AB1E's forte.
-1 byte thanks to @Neil.

Outputs an empty string if there is no result.

Try it online or verify all test cases.

Explanation:

"..."       # Recursive string explained below
     ©      # Store it in variable `®` (without popping)
      .V    # Evaluate and execute it as 05AB1E code
        ¯   # Push the global array
         à  # Pop and push its maximum
            # (which is output implicitly as result)

Ð           # Triplicate the current list
            # (which will be the implicit input-list in the first iteration)
 0å         # Pop one copy, and check if it contains a 0
   i  }     # If this is truthy:
    g       #  Pop another copy, and push its length
     ˆ      #  Pop and add this length to the global array
 <          # Then decrease all inner-most values in the ragged list by 1
  ε         # Map over the current list:
   D.ïië    #  If the current value is NOT an integer (aka it's a list):
        ®.V #   Do a recursive call on this list

Python, 64 63 bytes

-1 byte thanks to @LyricLy

f=lambda x,d=0:max(0!=i*0and f(i,d+1)or(d==i)*len(x)for i in x)

Attempt This Online!

Pyth, 23 bytes

MeSm?q0*0d*lHqdGghGdHg0

Attempt This Online!

Charcoal, 26 bytes

⊞υAFυFΦι⁺⟦⟧κ⊞υ⊖κI⌈EΦυ№ι⁰Lι

Try it online! Link is to verbose version of code. Outputs None if no subarray contains its depth. Explanation:

⊞υAFυFΦι⁺⟦⟧κ

Starting with the input array, perform a breadth-first search for subarrays.

⊞υ⊖κ

As each subarray is found, decrement the values in that subarray, so that the subarray will contain zero if it's at the correct depth. (Note that although the version of Charcoal on TIO fails to correctly decrement an empty list, the code already ignores empty lists as they can't contain their depth anyway.)

I⌈EΦυ№ι⁰Lι

Output the length of the longest subarray that contained its depth.