FastPrepPick the K Nearest Grid Points to (0, 0)
Problems/Pick the K Nearest Grid Points to (0, 0)

Pick the K Nearest Grid Points to (0, 0)

Capital One logoCapital One● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A January 2016 Capital One software engineer report from London lists k closest points to the origin next to a maximum sub-array question, in a process with a phone interview, a technical test and an onsite.

The report gives only the name. Here the points are integer pairs, closeness is straight-line distance, the answer lists the k nearest points from nearest to farthest, and points at the same distance keep their input order. There are up to 1000 points. These are our choices.

Our version is about 80% the same as the reported question.

Each entry points[i] = [x, y] names a spot on a grid. Choose the k spots nearest to (0, 0), measured as straight-line distance, and list them with the nearest first.

Spots equally far from (0, 0) are ranked by their position in points, earlier first; this decides which of several tied spots make the cut as well as their order. Return the spots themselves rather than distances.

Function

kClosest(points: int[][], k: int) → int[][]

Examples

Example 1

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

Squared distances from the origin: 100, 5, 18 and 25. The two smallest are [-2,1] (5) and [3,3] (18), listed nearest first.

Example 2

points = [[1,7],[4,4],[-7,1],[5,5],[2,2]]k = 3return = [[2,2],[4,4],[1,7]]

Squared distances: 50, 32, 50, 50, 8. [2,2] and [4,4] are nearest; then three points tie at 50 and the earliest in the input, [1,7], takes the last place.

Example 3

points = [[-1,2],[2,1],[0,0],[-2,-1]]k = 4return = [[0,0],[-1,2],[2,1],[-2,-1]]

All points are wanted. [0,0] is nearest, and the other three tie at squared distance 5, so they follow in input order.

Constraints

  • 1 <= k <= points.length <= 1000
  • -10^4 <= x, y <= 10^4

More Capital One interview questions

  • Count Records Present in A but Not BPHONE SCREEN · Seen Oct 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Maximum Subarray SumPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2025
  • Ten-Pin Bowling Frame ScoresPHONE SCREEN · Seen Nov 2023
  • Min StackPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2023
  • Invert a Binary TreePHONE SCREEN · Seen Dec 2020
  • Count How Often a Word Appears in a ParagraphPHONE SCREEN
  • In-Memory File System With Directory SizesPHONE SCREEN · ONSITE INTERVIEW
  • The Nth Number in the Fibonacci SequencePHONE SCREEN · ONSITE INTERVIEW
  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEW
  • Adaptive Calibration ErrorOpenAI · PHONE SCREEN
  • Find All Pythagorean TripletsDell Technologies · PHONE SCREEN
  • Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREEN
  • Optimal Central WarehouseGoogle · ONSITE INTERVIEW
  • Bootstrap Mean and Confidence IntervalAmazon · PHONE SCREEN
  • Find Missing and Duplicate IntegerInMobi · PHONE SCREEN
  • Build a Precision-Recall CurveMicrosoft · ONSITE INTERVIEW
  • Count Centaur Friend RequestsMeta · PHONE SCREEN
  • Minimum Fuel Car AlignmentFivetran · PHONE SCREEN
See Capital One hiring insights
Saved
class Solution {
    public int[][] kClosest(int[][] points, int k) {
        // Write your code here.
    }
}
Checking account…