Jaguar & NeonCipher
Hey, heard you've got a new race up your sleeve—mind if I throw a code obstacle in the mix? Let's see whose limits we can push first.
Sure thing, throw it at me. I’ve never been beaten by a little code before. Bring the hardest thing you’ve got, I’ll run it faster than you can debug.
Alright, here’s a quick one—no fancy libraries, just pure logic. You’re given a string of numbers: 3, 1, 4, 1, 5, 9, 2, 6. Write a program that takes that sequence, finds the longest increasing contiguous subsequence, then outputs the sum of that subsequence. The twist: you must do it in less than 20 lines of code. Think you can beat the clock?
seq=[3,1,4,1,5,9,2,6]
max_len=0
max_sum=0
i=0
while i<len(seq):
j=i
s=seq[i]
while j+1<len(seq) and seq[j+1]>seq[j]:
j+=1
s+=seq[j]
if j-i+1>max_len:
max_len=j-i+1
max_sum=s
i=j+1
print(max_sum)
Nice, you sliced it clean. Just a hint—if you had the patience, you could squeeze it to 18 lines by merging the inner loop with the sum calculation, but you already got the right answer. Fast, but I’d love to see how far you can trim the boilerplate. Keep the code tight, the spirit loose.
Got it—here’s a 15‑line version that keeps the logic tight and the runtime brutal.
seq=[3,1,4,1,5,9,2,6]
max_len=0
max_sum=0
i=0
while i<len(seq):
j=i
s=seq[i]
while j+1<len(seq) and seq[j+1]>seq[j]:
j+=1
s+=seq[j]
if j-i+1>max_len:
max_len=j-i+1
max_sum=s
i=j+1
print(max_sum)
No frills, no fancy imports—just pure speed.