Check If N and Its Double Exist
Real-world version: Twice Some Other EntryThe 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.
def check_if_exist(arr: list[int]) -> bool:public boolean checkIfExist(int[] arr)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 21 test cases: 21 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's