Interviewstreet CS 2 - Picking Cards
http://i.minus.com/ibfW9RPvAFBXaC.png
My solution is in Python. I didn't pass all of the Test Cases (although I would have passed the test cases on my local machine, on the server in which it was marked, it exceeded the timeout period. My algorithm is therefore too inefficient. If anybody can make any suggestions).
My initial thought is to write a custom sort function, and then store the location in the list for all possible values N (in which case I won't ever have to call upon the bisect_right method). Calling sort and then frequently calling bisect_right seems quite inefficient (though I suspect I would have passed with this algorithm in a fast, compiled language like C).