3Sum Closest

Medium · Arrays & Strings · about 15 minutes

Asked at Meta, Amazon, Bloomberg, Google, Microsoft.

Choose three entries of nums (from three different positions) so that their total lands as near to target as possible, and return that total. The inputs are such that only one total is the nearest.

Related guides