Trains the technique from
LeetCode 1346Check If N and Its Double ExistThis 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.
Example 1
The entry 14 at position 2 is double the entry 7 at position 0, and the two positions differ.
Example 2
Doubling 3 gives 6 and doubling 1 gives 2, neither of which is in the ledger, so no pair works.
Example 3
Zero at position 1 is double the zero at position 0, and those are two different positions.
Example 4
The entry -4 is double the entry -2.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def check_if_exist(arr: list[int]) -> bool:public boolean checkIfExist(int[] arr)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.