Hackerrank: Pairs

I solved this problem by two pointer approach at first. However, when I read the editorial, it mentioned using binary search tree. I found that is really clever, and decided to try that binary search tree to compare how fast it can run.

My code is on Github gist. Look them up if you are interested in how I wrote them. If you are interested in performance difference, keep reading.

This is the result with two pointer implementation: two pointer result

And here is the binary search implementation result: binary search result

Look at how fast binary search tree runs! This is amazing!! It runs by 0s for some test cases.

It is awesome that if you pick a right solution, your program solve the problem in incredible speed!