Created
January 23, 2015 02:52
-
-
Save val314159/206f22f6e729a9f1d302 to your computer and use it in GitHub Desktop.
get n from sparse array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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