alonsovidales / facebook-programming-challenges

This is a compilation of possible questions to be solved in order to be hired by Facebook
159 stars 54 forks source link

Bar game, O(nlogn) algorithm #1

Open amnn opened 11 years ago

amnn commented 11 years ago

I was having a look at your solution to the Bar game problem (thanks so much for uploading these problems by the way). And I think you can do it in O(nlogn) where n is the number of numbers.

The algorithm is this:

Here it is in C++ (the O(nlogn) comes from the insertion sort, for which I used a standard C++ STL set): Solution