J, 21 14 bytes
Saved 7 bytes thanks to miles and (indirectly) Jonathan!
{.@/:#@":"0,.-
This is a four-chain:
{.@/: (#@":"0 ,. -)
Let's walk over the input 10 27 232 1000
. The inner fork consists of three tines. #@":"0
calculates the sizes, ,.
concats each size with its negated (-
) member. For input 10 27 232 1000
, we are left with this:
(#@":"0 ,. -) 10 27 232 1000
2 _10
2 _27
3 _232
4 _1000
Now, we have {.@/:
as the outer tine. This is monadic first ({.
) over dyadic sort (/:
). That is, we'll be taking the first element of the result of dyadic /:
. This sorts its right argument according to its left argument, which gives us for our input:
(/: #@":"0 ,. -) 10 27 232 1000
27 10 232 1000
Then, using {.
gives us the first element of that list, and we are done:
({.@/: #@":"0 ,. -) 10 27 232 1000
27
Old version
>./@(#~]=<./@])#@":"0
Still working on improvements. I golfed it down from 30, and I think this is good enough. I'm going to first break it down into basic parts:
size =: #@":"0
max =: >./
min =: <./
over =: @
right =: ]
left =: [
selectMin =: #~ right = min over right
f =: max over selectMin size
f 3 4 5
5
f 3 4 53
4
f 343 42 53
53
Here's how this works.
>./@(#~ ] = <./@]) #@":"0
This is a monadic train, but this part is a hook. The verb >./@(#~ ] = <./@])
is called with left argument as the input to the main chain and the sizes, defined as #@":"0
, as the right argument. This is computed as length (#
) over (@
) default format (":
), that is, numeric stringification, which is made to apply to the 0-cells (i.e. members) of the input ("0
).
Let's walk over the example input 409 12 13
.
(#@":"0) 409 12 13
3 2 2
Now for the inner verb, >./@(#~ ] = <./@])
. It looks like >./@(...)
, which effectively means maximum value (>./
) of (@
) what's inside (...)
. As for the inside, this is a four-train, equivalent to this five-train:
[ #~ ] = <./@]
[
refers to the original argument, and ]
refers to the size array; 409 12 13
and 3 2 2
respectively in this example. The right tine, <./@]
, computes the minimum size, 2
in this case. ] = <./@]
is a boolean array of values equal to the minimum, 0 1 1
in this case. Finally, [ #~ ...
takes values from the left argument according the right-argument mask. This means that elements that correspond to 0
are dropped and 1
retained. So we are left with 12 13
. Finally, according to the above, the max is taken, giving us the correct result of 13
, and we are done.