The "Check If N and Its Double Exist interview question" asks you to determine if an array contains two different indices i and j such that arr[i] == 2 * arr[j]. For example, in [10, 2, 5, 3], both 10 and 5 exist (), so the condition is met.
Companies like Meta, Amazon, and Google use the "Check If N and Its Double Exist coding problem" as a warm-up. It tests a candidate's ability to use a "Hash Table interview pattern" to solve search problems in time. It also requires careful handling of the number zero and non-integer divisions.
This problem is best solved using a Hash Set for Lookups.
x in the array.2 * x?x / 2 (if is even)?x to the set.Array: [7, 1, 14, 11]
x / 2 without verifying if is even (e.g., if , might be 3 in integer math, leading to a false positive if 3 is in the set).Hash Tables/Sets are the most common tool for "existence" problems. Practice identifying when a problem requires finding a relationship between two elements—a set is almost always the optimal choice.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Intersection of Two Arrays II | Easy | Solve | |
| Intersection of Two Arrays | Easy | Solve | |
| K-diff Pairs in an Array | Medium | Solve | |
| Minimum Common Value | Easy | Solve | |
| Largest Positive Integer That Exists With Its Negative | Easy | Solve |