Skip to content

Instantly share code, notes, and snippets.

@1328
Created May 1, 2026 19:42
Show Gist options
  • Select an option

  • Save 1328/5bc87c23076faae9ce9002b4a247d117 to your computer and use it in GitHub Desktop.

Select an option

Save 1328/5bc87c23076faae9ce9002b4a247d117 to your computer and use it in GitHub Desktop.
def merge(a_list,b_list):
a_it = iter(a_list)
b_it = iter(b_list)
a = next(a_it, None)
b = next(b_it, None)
while True:
if a is None:
yield b # clear buffer
yield from b_it
break
if b is None:
yield a # clear buffer
yield from a_it
break
if a<b:
yield a
a = next(a_it, None)
else:
yield b
b = next(b_it, None)
def solve(a, b):
total = len(a) + len(b)
odd = total % 2
mid = (total-1) // 2
it = merge(a,b)
count = 0
for idx, x in enumerate(it):
if idx != mid:
continue
if odd:
return x
else:
return (x + next(it))/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment