Hash map · Easy
A reconciliation check needs two distinct batch entries whose amounts add to a requested total. Entries may have equal amounts but the same entry cannot be used twice. The check only needs existence, not indexes or a list of all matching pairs.
Return whether two different indexes in the supplied amount array have values that sum exactly to the target.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: integer[], target: integer }
Fields
- nums is an unsorted array of signed integer amounts; target is the required sum.
Output
Return value
- Return a boolean. Duplicate amounts are allowed, but two distinct occurrences are required.
- Empty and single-entry batches return false.
Constraints
- 0 <= nums.length <= 100000; each value is an integer between -1000000000 and 1000000000.
- -2000000000 <= target <= 2000000000.
Examples
Example 1
{
"nums": [
4
],
"target": 8
}Returns
falseExample 2
{
"nums": [
4,
4
],
"target": 8
}Returns
trueRequired complexity
O(n) expected time and O(n) auxiliary space