πŸ“ Problem Details

πŸ’­What Were My Initial Thoughts?

brute force approach would be to check every pair of elements for our conditions

πŸ€”What Did I Struggle With?

i dont think i was able to find the hashmap solution during the mock

πŸ’‘ Explanation of Solution

- use an unordered set `seen`
- iterate through the input array
	- for each element x:
		- check if 2*x or x/2 exist in our set
		- if true, return true
	- otherwise, add x to the set
- if no pair is found after iterating through the array, return false

βŒ› Complexity Analysis

Time Complexity: O(n)
Space Complexity: O(n)

πŸ’» Implementation of Solution

bool checkIfExist(vector<int>& arr) {
    unordered_set<int> seen;
    for (int x : arr) {
        if (seen.count(2 * x) || (x % 2 == 0 && seen.count(x / 2))) {
            return true;
        }
        seen.insert(x);
    }
    return false;
}