FastPrepK Closest Points to a Query Point
Problems/K Closest Points to a Query Point

K Closest Points to a Query Point

Uber logoUber● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report does not say how ties are handled or what order the output is in. Our version is about 97% the same as the reported question.

Given distinct planar integer points points, a query point query, and an integer k, return the k points with the smallest squared Euclidean distance from query.

Order the result by increasing squared distance, then increasing x, then increasing y.

Function

kClosestToQuery(points: int[][], query: int[], k: int) → int[][]

Examples

Example 1

points = [[1,3],[-2,2],[2,-2]]query = [0,0]k = 2return = [[-2,2],[2,-2]]

Both returned points have squared distance 8; lexicographic coordinates break the tie.

Example 2

points = [[2,3],[5,5],[-1,0]]query = [1,1]k = 2return = [[-1,0],[2,3]]

The squared distances are 5, 32, and 5; coordinate order resolves the tie at distance 5.

Constraints

  • points is non-empty and contains distinct coordinate pairs.
  • query contains exactly two signed integers.
  • 1 <= k <= points.length.
  • Every squared distance fits in a signed 64-bit integer.

More Uber Onsite Interview questions

  • Random Bingo Card GeneratorONSITE INTERVIEW · Seen Dec 2026
  • Travelers per Consecutive City TripletONSITE INTERVIEW · Seen Dec 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Serialize and Deserialize an N-Ary TreeONSITE INTERVIEW · Seen Oct 2026
  • Longest Continuous Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Oct 2026
  • K Smallest Squares from a Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
  • Grid Robot Route with Charging PrioritiesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Shortest Increasing Path to a TargetONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • K Closest Points to a TargetAsana · ONSITE INTERVIEW
  • Top K Frequent Closest PointsGoogle · PHONE SCREENGoogle interview questions
  • The k Points Nearest the OriginAdobe · PHONE SCREENAdobe interview questions
  • K Closest Points to the OriginSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Minimum Meeting RoomsOracle · ONSITE INTERVIEWOracle interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Top K Frequent WordsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int[][] kClosestToQuery(int[][] points, int[] query, int k) {
        // TODO: return the deterministically ordered k closest points.
    }
}
Checking account…