Perl, 3838 37 bytes
Includes +1 for -pa
Give input on STDIN:
perl -M5.010 maxmin.pl <<< "3451 29820 2983 1223 1337"
maxmin.pl
:
#!/usr/bin/perl -a
\$G[99-y///c][$_]for@F;say$#{$G[-1]}
Uses memory linear in the largest number, so don't try this on too large numbers. A solution without that flaw is 38 bytes:
#!/usr/bin/perl -p
$.++until$\=(sort/\b\S{$.}\b/g)[-1]}{
This isAll of these are very awkward and doesn'tdon't feel optimal at all...