Given a target number and a list of numbers, find a triplet of numbers from the list such that the sum of that triplet is the closest to the target. Return that sum.
There are two triplets that sum up to a number that is 2 away from the target: 11 - 6 + 9 = 14 and 11 - 2 + 9 = 18. No triplets sum up to anything closer than that. Therefore, 14 and 18 are correct outputs.
Learn what Combination Sum is and how to generate all combinations with sum equal to target problem.
Learn how you can find 2 Sum in a Sorted Array problem.
Learn how you can divide two subsequences with equal sums by solving the Equal Subset Sum Partition Problem.
We hope that these solutions to the 3Sum Closest problem will help you level up your Two Pointers technique. Companies such as Amazon, Facebook, Microsoft, LinkedIn, Airbnb, Oracle, etc., include 3Sum Closest interview questions in their tech interviews.
If you are preparing for a tech interview at FAANG or any other Tier-1 tech company, register for Interview Kickstart’s FREE Webinar to understand the best way to prepare.
Interview Kickstart offers interview preparation courses taught by FAANG+ tech leads and seasoned hiring managers. Our programs include a comprehensive curriculum, unmatched teaching methods, FAANG+ instructors, and career coaching to help you nail your next tech interview.
We offer 17 interview preparation courses, each tailored to a specific engineering domain or role, including the most in-demand and highest-paying domains and roles, such as:
To learn more, register for the FREE Webinar.