Solution for problem 42. Implemented binary search on array for lookup to save space.