Monday, January 8, 2018

One algorithm 3 solutions

January 8, 2018

Introduction


It is less challenge to work on algorithm in mock interview since I already have practiced over five round. So at least I have solved the same algorithm over 5 times. I had to solve the algorithm called pair with difference, but the problem solving has no difference. I could not memorize anything, I read the problem again, and then think about the ideas, and then explain first two ideas, using hashtable, using binary search.


Algorithm practice


The peer asked me to solve the algorithm using binary search first. After I finished the binary search to solve the algorithm, the peer told me that there is another solution using O(n) time to find pair after sorting. So I wrote two pointer techniques as well.

Here is the code using O(n) time to find pair after sorting. Here is the solution to use binary search.




No comments:

Post a Comment