Skip to content

Instantly share code, notes, and snippets.

@val314159
Created January 23, 2015 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save val314159/206f22f6e729a9f1d302 to your computer and use it in GitHub Desktop.
Save val314159/206f22f6e729a9f1d302 to your computer and use it in GitHub Desktop.
get n from sparse array
def get_index(arr,n):
"""
arr is in a sparse form
"""
pos=0
ret=arr[0][0]
seen=1
for x in xrange(n):
seen+=1
if seen>arr[pos][1]:
seen=1
pos+=1
ret=arr[pos][0]
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment