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 Protect the Cities problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Protect the Cities problem solution There are N cities in Imaginary Land. The President of Imaginary Land uses the Cartesian coordinates. Each city is located at some point with integer coordinates. The President is very careful and concerned about the well-being of the citizens of his country.
For that reason, he wants to create a boundary and cover all the cities inside that boundary. The boundary should be in the shape of a square and should be parallel to the coordinate axes. Find the minimum area enclosed by the boundary such that all the cities are on or inside the boundary.
HackerEarth Protect the Cities problem solution

HackerEarth Protect the Cities problem solution.

#include<bits/stdc++.h>
using namespace std;

int main()
{
long long int n;
cin >> n;
long long int x[n + 1], y[n + 1];
for(int i = 0; i < n; i++)
cin >> x[i] >> y[i];
long long int maxx, maxy;
long long int minx, miny;
maxx = maxy = (long long)(-1e18);
minx = miny = (long long)(1e18);
for(int i=0;i<n;i++)
{
maxx = max(maxx, x[i]);
minx = min(minx, x[i]);
maxy = max(maxy, y[i]);
miny = min(miny, y[i]);
}
long long ans = max(maxx - minx, maxy - miny);
ans *= ans;
cout << ans << 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