Hash maps and frequency: Given nums and target, count index pairs (i, j) where i < j and nums[i] + nums[j] equals target. Equal values at different indexes count as different pairs.
Input: A JSON object { "nums": number[], "target": number }.
Output: A JSON integer equal to the number of valid index pairs.
Constraints:
- 0 <= nums.length <= 100000
- nums may contain duplicates and negative values
- Do not reuse the same index in a pair
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: HARD. Variant: 18. Favor a pragmatic solution that is easy to ship, read, and adapt.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked hard difficulty.
The signed-in workspace provides the tools requir