Pair With a Target Sum
Easy · Pair With a Target Sum
You get an integer array `values` and an integer `goal`. Find two different elements whose sum is exactly `goal` and return their indices (0-based). The input is guaranteed to contain exactly one such pair. You cannot use the same element twice, although two different elements may hold the same value. The indices may be returned in either order. The O(n²) approach is obvious; try to do better.…
Solve the problem →