Show problems as
Classic problem #1346EasyArrayHash TableTwo PointersBinary SearchSorting

Check If N and Its Double Exist

Real-world version: Twice Some Other Entry
Tracked in this browser only
Read Check If N and Its Double Exist on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A ledger holds arr, a list of signed adjustments. An adjustment can be negative, zero or positive, and the same amount can appear at more than one position.

Return true when the ledger holds two entries at different positions i and j such that arr[i] is exactly double arr[j], and false otherwise. Because the two positions have to differ, a ledger with a single zero in it does not qualify on that zero alone, while a ledger holding zero at two positions does.

Examples

Example 1

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

The entry 14 at position 2 is double the entry 7 at position 0, and the two positions differ.

Example 2

Input
arr = [3, 1]
Output
false

Doubling 3 gives 6 and doubling 1 gives 2, neither of which is in the ledger, so no pair works.

Example 3

Input
arr = [0, 0]
Output
true

Zero at position 1 is double the zero at position 0, and those are two different positions.

Example 4

Input
arr = [-2, -4]
Output
true

The entry -4 is double the entry -2.

Constraints

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

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def check_if_exist(arr: list[int]) -> bool:
Java
public boolean checkIfExist(int[] arr)