Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth K Devices problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth K Devices problem solution, You are given the location of N devices on a coordinate plane and an integer K. Location of the ith device is donated by (Xi, Yi). A modem is located at (0,0). The range of modem is circular. All the devices within the range of the modem will connect to the modem.
 
You have to find the minimum integral radius of the circular range of the modem such that at least K devices will connect to the modem.
 
 
HackerEarth K Devices problem solution

 

 

HackerEarth K Devices problem solution.

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 5;
long long x[MAX], y[MAX], dis[MAX];

int main(int argc, char* argv[])
{
if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
if(argc == 3) freopen(argv[2], "w", stdout);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
for (int i = 0; i < n; i++) {
cin >> y[i];
}
for (int i = 0; i < n; i++) {
dis[i] = x[i]*x[i] + y[i]*y[i];
}
sort(dis, dis + n);
cout << ceil(sqrt(dis[k-1])) << endl;
return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes