Step 1 of 813% Complete
Coding Skills
1. Coding & Data Structures
You need to find if any two numbers in an unsorted array of N elements sum up to a target T. How would you solve this with minimal time complexity?
Use nested loops to check all pairs: O(NΒ²) time, O(1) space.
Sort the array first O(N log N) then use two pointers: O(1) space.
Store complements in a Hash Map in a single pass: O(N) time, O(N) space.
Convert to a binary search tree: O(N log N) time.