Skip to content

Instantly share code, notes, and snippets.

@johnpaulhayes
Created October 22, 2013 09:56
Show Gist options
  • Save johnpaulhayes/7098027 to your computer and use it in GitHub Desktop.
Save johnpaulhayes/7098027 to your computer and use it in GitHub Desktop.
Query two arrays for the k-th largest
a = [1, 5, 10, 15]
b = [3, 6, 8, 20]
def query_arrays(a, b, k):
i,j=0,0
merged_array = []
while i <= len(a)-1 and j <= len(b)-1:
if a[i] < b[j]:
merged_array.append(a[i])
i += 1
else:
merged_array.append(b[j])
j += 1
print merged_array
print merged_array[len(merged_array)-k]
query_arrays(a, b, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment