Check If N and Its Double Exist

Easy

Description

Given an array arr, check if there exists two indices i and j such that i != j, arr[i] == 2 * arr[j].

Examples

Input:arr = [10,2,5,3]
Output:true
Explanation:

arr[0] = 10 = 2 * arr[2]

Input:arr = [10, 2, 5, 3]
Output:true
Explanation:

arr[0] = 10 = 2 * arr[2] (10 = 2*5), so a double exists.

Input:arr = [7,1,14,11]
Output:true
Explanation:

arr[2] = 14 = 2 * arr[0] (since 14 = 2 * 7). The indices i=2 and j=0 are different and satisfy the condition.

Constraints

  • 2 ≤ arr.length ≤ 500

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!