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 Perpendicular Lines problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Perpendicular Lines problem solution You are given 4 points of the form (xi, yi) in the 2D plane, find out if the lines formed by (x1, y1), (x2, y2), and (x3, y3), (x4, y4) are perpendicular to each other.
HackerEarth Perpendicular Lines problem solution

HackerEarth Perpendicular Lines problem solution.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d", &x)
#define sc(x) scanf("%c", &x)
#define sl(x) scanf("%lld", &x)
#define pl(x) printf("%lldn", x)
#define pi(x) printf("%dn", x)
#define gu getchar_unlocked
#define pu putchar_unlocked
#define setbits __builtin_popcountll
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define speed ios::sync_with_stdio(false)

ll gcd(ll a, ll b){
if(b == 0){
return a;
}
else{
return gcd(b, a % b);
}
}


int main(){
int t;
si(t);
while(t--){

ll x1, x2, x3, x4, y1, y2, y3, y4, m1num, m2num, m1den, m2den;
sl(x1); sl(y1); sl(x2); sl(y2);
sl(x3); sl(y3); sl(x4); sl(y4);

if(x1 == x2 && y1 == y2){
printf("INVALIDn");
}
else if(x3 == x4 && y3 == y4){
printf("INVALIDn");
}
else{
m1num = y2 - y1; m1den = x2 - x1;
m2num = y4 - y3; m2den = x4 - x3;

if(m1den == 0 && m2den == 0){
printf("NOn");
}
else if(m1den == 0){
if(m2num == 0){
printf("YESn");
}
else{
printf("NOn");
}
}
else if(m2den == 0){
if(m1num == 0){
printf("YESn");

}
else{
printf("NOn");
}
}
else{
int neg = 0;
if(m1num < 0){
neg++;
}
if(m2num < 0){
neg++;
}
if(m1den < 0){
neg++;
}
if(m2den < 0){
neg++;
}

ll p = gcd(abs(m1num), abs(m1den));
ll q = gcd(abs(m2num), abs(m2den));
m1num /= p; m1den /= p;
m2num /= q; m2den /= q;

if(abs(m1num) == abs(m2den) && abs(m2num) == abs(m1den) && neg % 2 == 1){
printf("YESn");
}
else{
printf("NOn");
}
}

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