shlogg · Early preview
Md Ariful Haque @mah-shamim

Check If N And Its Double Exist In Array

Check if N and its double exist in an array using a hash table. Iterate through the array, checking for each element if its double or half has been encountered. Return true if found, false otherwise.

1346. Check If N and Its Double Exist
Difficulty: Easy
Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting
Given an array arr of integers, check if there exist two indices i and j such that :

i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]

Example 1:

Input: arr = [10,2,5,3]
Output: true
Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j]

Example 2:

Input: arr = [3,1,7,11]
Output: false
Explanation: There is no i and j that satisfy the conditions.

Constraints:

2 <= arr.length <= 500
-103 <= arr[i] <= 103

Hint:

Loop from i = 0 to arr.length, maintaining...