All problems
0620EasyArrayHash TableTwo PointersBinary SearchSorting

Twice Some Other Entry

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1346Check If N and Its Double Exist

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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