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
Programmingoneonone
Programmingoneonone

HackerEarth Cities and coordinates problem solution

YASH PAL, 31 July 2024
In this HackerEarth Cities and co-ordinates 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 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 Cities and co-ordinates problem solution

HackerEarth Cities and coordinates 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

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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