Don't leave your software engineering career path to chance. Make sure you're interview-ready with Exponent's software developer interview prep course. Start free. bit.ly/3iOyWCy
@yanciliang77353 күн бұрын
Thanks for providing such a great example! I recently completed the 2-sum problem and was excited to quickly find the approach of assuming one element as part of the target combination. This simplifies the problem into a 2-sum problem. It’s also fun to consider how the optimal solution shifts when the problem evolves from 2-sum to 3-sum. For instance, hashing, which offers O(n) time complexity for 2-sum, is no longer the best choice for 3-sum because we inevitably need at least O(n²) time due to the additional loop. This makes the pointer-based approach, with its O(n log n) sorting overhead, more feasible and efficient. It’s intriguing to see how the nature of the problem changes the optimal solution.
@ruspatel19962 жыл бұрын
Great work! I love how you worked from a naive solution to solving a smaller problem (2 sum) to applying the solution of the smaller problem to a larger problem. Also great work on showing why sorted/pointer method was better than hash set method.