New answers tagged

1 vote

Compute maximum excluding the current position

Scala 3, 109 bytes 109 bytes, it can be golfed more. Any improvement would be appreciated. Golfed version. Attempt This Online! ...
138 Aspen's user avatar
  • 5,391
1 vote

Compute maximum excluding the current position

APL+WIN, 22 bytes Prompts for vector. Index origin = 0 ⌈/0 1↓(⍳⍴n)⌽(2⍴⍴n)⍴n←⎕ Try it online! Thanks to Dyalog Classic
Graham's user avatar
  • 5,916
2 votes

Compute maximum excluding the current position

J, 20 19 bytes (]{~[=0{])(2$,\:,)/ Attempt This Online! Copy of my answer in chat to the CMC version of this challenge. -1 byte thanks to Jonah by spotting ...
Bubbler's user avatar
  • 75.2k
1 vote

Compute maximum excluding the current position

Python 3.8 (pre-release), 72 66 bytes def f(A):B=len(A)*[A.pop(i:=A.index(max(A)))];B[i]=max(A);return B Try it online! First, observe that ...
movatica's user avatar
  • 1,114
1 vote

Compute maximum excluding the current position

Perl 5 -MList::Util=max,first -a, 81 bytes $m=max@F;$i=first{$F[$_]==$m}@t=0..$#F;$;=max@F[grep$i-$_,@t];say$_-$i?$m:$;for@t ...
Xcali's user avatar
  • 14.4k
2 votes

Compute maximum excluding the current position

Google Sheets, 49 bytes =let(a,A1:E1,m,max(a),sort(if(a=m,large(a,2),m))) Put the input in cells A1:E1 and the formula in cell <...
doubleunary's user avatar
  • 1,478
4 votes

Compute maximum excluding the current position

Jelly, 13 bytes œṡFṀṭʋṀiⱮCị⁸ʋ A monadic Link that accepts the list and yields the maximised version. Try it online! How? ...
Jonathan Allan's user avatar
4 votes

Compute maximum excluding the current position

J, 21 bytes (={],1>./@}.i.|.[)>./ Try it online! Thanks to Jonathan Allen for pointing out I had missed the linear time constraint. This answer fixes that. ...
Jonah's user avatar
  • 33.3k
1 vote

Compute maximum excluding the current position

Charcoal, 26 bytes ≔⌈θη≔⌕θηζ≔⌈Φθ⁻κζζIEθ⎇⁼ιηζη Try it online! Link is to verbose version of code. Explanation: ≔⌈θη Get the ...
Neil's user avatar
  • 169k
4 votes

Compute maximum excluding the current position

Haskell + hgl, 34 bytes zW ma<tl<g rS*^g lS g h=h ma~<mn Attempt This Online! Explanation First this calculates the ...
Wheat Wizard's user avatar
  • 97.8k
2 votes

Compute maximum excluding the current position

Python + NumPy, 44 bytes lambda L:L[L.argpartition(-2)[(L<max(L))-2]] Attempt This Online! Takes and returns NumPy arrays. ...
Albert.Lang's user avatar
  • 2,539
3 votes

Compute maximum excluding the current position

C (GCC) -lm, 97 93 90 104 101 bytes -2 bytes thanks to @Arnauld -1 byte thanks to @att +14 bytes due to a bug fix (m was ...
Mukundan314's user avatar
  • 8,484
1 vote

Compute maximum excluding the current position

APL(NARS), 119 chars r←f w;a;b;n;i;t n←≢w⋄i←2⋄a←b←w[1] →4×⍳i>n⋄→3×⍳∼b<t←w[i]⋄a←b⋄b←t i+←1⋄→2 i←1⋄r←⍬ t←w[i]⋄→6×⍳∼t=b⋄r,←a⋄→7 r,←b →5×⍳n≥i+←1 15+17+29+7+7+23+...
Rosario's user avatar
  • 301
3 votes

Compute maximum excluding the current position

Python 3, 71 bytes def f(a):h=nlargest(2,a);return[h[x>h[1]]for x in a] from heapq import* Try it online! -4 bytes thanks to movatica Compute the first and ...
Stef's user avatar
  • 869
5 votes

Compute maximum excluding the current position

JavaScript (ES6), 54 bytes -2 thanks to @l4m2 a=>a.map(v=>v-a?a:m,a.map(v=>a>v?m>v?0:m=v:(m=a,a=v))) Try it online! Method During the first pass, ...
Arnauld's user avatar
  • 191k
2 votes

Compute maximum excluding the current position

JavaScript (Node.js), 71 bytes x=>x.map(v=>v-n?m:M(...x.filter(u=>u-n||0*++n)),m=n=M(...x)) M=Math.max Try it online! -1 byte from Arnauld After first ...
l4m2's user avatar
  • 22.3k
1 vote

Output intervals for the optimal subarrays

Python 3, 484 bytes ...
CursorCoercer's user avatar

Top 50 recent answers are included