Check If N and Its Double Exist

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]

Return true if such indices exist, otherwise return false.

Example 1
Inputarr = [10,2,5,3]
Outputtrue
For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j].
Example 2
Inputarr = [3,1,7,11]
Outputfalse
There is no i and j that satisfy the conditions.

Constraints

  • 2 <= arr.length <= 500
  • -10^3 <= arr[i] <= 10^3

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate