FunctionRacerProblemsRace

Pairs Hitting Target

MediumNumPyPython

Count the pairs of positions i < j for which nums[i] + nums[j] == target. Return an int. Hint: build the table of all pair sums with broadcasting, then keep only the part above the diagonal (np.triu with k=1, or compare index grids).

Example 1

nums [1,2,3,4]
target 5
returns 2

The pairs 1+4 and 2+3 work.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems