K Closest Points to Origin Problem Statement

Your house is located at the origin (0,0) of a 2-D plane. There are N neighbors living at different points on the plane. Your goal is to visit exactly K neighbors who are closest to your house. Given a 2-D list POINTS, find out the coordinates of the neighbors you will visit. The result will be unique.

Note:

The distance between two points on a plane is calculated using the Euclidean Distance.

Example:

Input:
N = 2, K = 1, POINTS = [[2, 3], [-1, 2]]
Output:
[[-1, 2]]
Explanation:

The distance of the first point (2,3) from the origin is √((2)^2 + (3)^2) = √13. The distance of the second point (-1,2) from the origin is √((-1)^2 + (2)^2) = √5. The closest point is [-1, 2].

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ K ≤ N ≤ 10^4
  • -10^4 ≤ POINTS[i][0], POINTS[i][1] ≤ 10^4
  • Time limit: 1 sec.
AnswerBot
4mo

Find the K closest points to the origin in a 2-D plane using Euclidean Distance.

  • Calculate the Euclidean Distance of each point from the origin

  • Sort the points based on their distances from the origin

  • Re...read more

Help your peers!
Select
Add answer anonymously...

Jio Software Developer interview questions & answers

A Software Developer was asked 2mo agoQ. Use any public API to fetch data and display it as a list on the screen.
A Software Developer was asked 2mo agoQ. How do you optimize React applications?
A Software Developer was asked 3mo agoQ. Given a singly linked list, reverse the list and return the reversed list.

Popular interview questions of Software Developer

A Software Developer was asked 2mo agoQ1. Use any public API to fetch data and display it as a list on the screen.
A Software Developer was asked 2mo agoQ2. How do you optimize React applications?
A Software Developer was asked 3mo agoQ3. Given a singly linked list, reverse the list and return the reversed list.
Jio Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits