26. Check if N and Its Double Exist

EasyArrayArray

Given an integer array arr, check if there exist two indices i and j such that i != j, arr[i] == 2 * arr[j], and return true if so, else false.

Input: An integer array arr.

Output: true if N and 2*N both exist (at different indices), else false.

Examples

Example 1
Input: [10,2,5,3]
Output: true
Explanation: 10 = 2*5. Both exist. Return true.
Example 2
Input: [3,1,7,11]
Output: false
Explanation: No pair N,2N exists. Return false.
Example 3
Input: [0,0]
Output: true
Explanation: 0 = 2*0. Two zeros exist at different indices. Return true.

Constraints

Asked by

GoogleBloombergAmazonMetaMicrosoft
Solve this problem in the editor →