Tag Info

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! ...
• 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
• 5,916

• 14.4k

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 <...
• 1,478

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? ...
• 105k

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. ...
• 33.3k
1 vote

Compute maximum excluding the current position

Charcoal, 26 bytes ≔⌈θη≔⌕θηζ≔⌈Φθ⁻κζζＩＥθ⎇⁼ιηζη Try it online! Link is to verbose version of code. Explanation: ≔⌈θη Get the ...
• 169k

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 ...
• 97.8k

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. ...
• 2,539

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 ...
• 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+...
• 301

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 ...
• 869

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, ...
• 191k

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 ...
• 22.3k
1 vote

Output intervals for the optimal subarrays

Python 3, 484 bytes ...
• 4,107

Top 50 recent answers are included