FastPrepThree Sum Closest
Problems/Three Sum Closest

Three Sum Closest

Expedia logoExpedia● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for three values and, on a tie, the smaller sum. The two-value approach pasted in the report does not fit, so we did not follow it. We chose the limits. Our version is about 95% the same as the reported question.

Choose three different positions in nums. Return the sum whose absolute difference from target is smallest.

If several sums are equally close, return the smaller sum. Values may repeat, but a position may be used only once. The input order does not affect the answer.

Function

threeSumClosest(nums: int[], target: int) → int

Examples

Example 1

nums = [-1,2,1,-4]target = 1return = 2

The closest sum is -1 + 2 + 1 = 2.

Example 2

nums = [0,0,0]target = 1return = 0

The only possible sum is 0.

Example 3

nums = [-2,0,2,4]target = 1return = 0

Sums 0 and 2 are both one away, so the smaller sum 0 is returned.

Constraints

  • 3 <= nums.length <= 1000.
  • -10^4 <= nums[i], target <= 10^4.
  • The answer fits in a signed 32-bit integer.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • 4SumAmazon · ONSITE INTERVIEW
  • Count Triplets With Sum at Most TargetGoogle · ONSITE INTERVIEWGoogle interview questions
  • Sort ColorsCapital One · ONSITE INTERVIEWCapital One interview questions
  • 3SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • 3SumMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Next and Previous Lexicographic PermutationAdobe · ONSITE INTERVIEWAdobe interview questions
  • Sort ColorsInfosys · ONSITE INTERVIEWInfosys interview questions

Interview reports that mention this question

  • Expedia New Grad SDE Oldest Loops: 4 Experiences (Part 3 of 3)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int threeSumClosest(int[] nums, int target) {
      // write your code here
    }
}
Checking account…