You are viewing a single comment's thread. Return to all comments →
For the binary search, aren't we supposed to sort the array of costs first? that's gonna be O(nlog(n)). then we will have to search the target for each one of the elements (worst case) of the array which will make it O(nlog(n)). I guess hash tables with the overall complexity of O(n) would be better than O(nlog(n)). I'm writing this to learn if there is a better solution than hash tables so I would appreciate your feedback.