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

HackerEarth K Devices problem solution

YASH PAL, 31 July 202411 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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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