Jay
Jay 1
I've been stuck in this room for some time now. They locked me in here and told
me the only way I can leave is if I solve their problem within five seconds.
I've tried so much, but my algorithm keeps going over the time. Can you help me?
What I have to do is find the maximum contiguous sub-array within this array of
numbers. They keep telling me my algorithm isn't efficient enough! If you can
send me the indices of this array, I might live to see another day.
Format: "sum, i, j" Example: 103, 345, 455
sum = the maximum contiguous sum
i = start index of sub-array
j = end index of sub-array
Press Enter to get the arrfrom pwn import *
conn = remote('chals3.umdctf.io', 6001)
conn.send('\n')
conn.recvuntil('[')
data = '[' + conn.recvuntil(']').decode()
print(data)
arr = eval(data)
max_so_far = 0
max_end_here = 0
curr_index = 0
curr_i = 0
i = 0
j = 0
while curr_index < len(arr):
max_end_here += arr[curr_index]
if max_end_here > max_so_far:
max_so_far = max_end_here
i = curr_i
j = curr_index
if max_end_here < 0:
max_end_here = 0
curr_i = curr_index + 1
curr_index += 1
print(f"{max_so_far}, {i}, {j}")
conn.send(f"{max_so_far}, {i}, {j}")
conn.recvline()
conn.recvline()
print(conn.recvline())
print(conn.recv())
conn.close()
Jay 2

Last updated