We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your solution "pays" O(nlogn) time in order to do the (unnecessary) sorting. Yes, it is simple and sometimes simplicity is preferred to performance. Yet, in an interview, you need to at least make clear to your interviewer that you are doing this in favor of simplicity and that you know that it is not the optimal solution.
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
Your solution "pays" O(nlogn) time in order to do the (unnecessary) sorting. Yes, it is simple and sometimes simplicity is preferred to performance. Yet, in an interview, you need to at least make clear to your interviewer that you are doing this in favor of simplicity and that you know that it is not the optimal solution.
Here is a Java 8 approach: