Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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 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

Related website

The Computer Science

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes