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

HackerEarth The savior? 3 problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth The savior? [3] problem solution Fatal Eagle is trying his best to save his city, but he’s failing to do so. He knows he needs some external help; some guidance, something… something out of ordinary to defeat this powerful enemy called Mr. XYZ.
 
“Find out the number of pairs in the list you’ve made, who sum up to an even number!”
 
“Who are you? And what do you mean? Can you elaborate a bit?” Exclaims Fatal Eagle.
 
“I meant, what I said… take a look at the sample explanation of the problem I want you to solve, you’ll understand perhaps. And as for who I am? I’m Arjit and like you, I just want to save this city, too.”
 
Fatal Eagle is quick to respond to Arjit’s task, and decides to solve it quickly. He takes out the list of integers which contains the powers of weird creatures, and starts finding out the number of pairs which sum up to an even number. Here’s how he does it:
 
Let’s say that he had a list of 4 numbers: [1, 2, 3, 4] His answer would be: 2. How? 1+3 = 4 and 2 + 4 – that is to say, a number will NOT be added to itself and 1+3 is same as 3+1.
 
 
HackerEarth The savior? [3] problem solution

 

 

HackerEarth The savior? 3 problem solution.

tc = int(raw_input())
while tc>0:
tc = tc - 1
n = int(raw_input())
l = map(int, raw_input().split())
ans = 0
for i in xrange(n):
for j in xrange(n):
if l[i]==l[j]:
pass
else:
if (l[i]+l[j])%2==0:
ans = ans + 1
print ans/2
 

Second solution

#include <bits/stdc++.h>

void assert_digit() {char c = getchar(); assert('0' <= c && c <= '9'); ungetc(c, stdin);}

using namespace std;

int N;

int main()
{
assert_digit();
int TEST;
scanf("%d", &TEST);
assert(getchar()=='n');
assert(1<=TEST && TEST<=50);
while(TEST--)
{
assert_digit();
scanf("%d", &N);
assert(getchar()=='n');
assert(1<=N && N<=1000);
int cnt[2]={0, 0};
unordered_map<int, int> cnt2;
for(int i=0; i<N; i++)
{
int a;
assert_digit();
scanf("%d", &a);
if(i!=N-1)
assert(getchar()==' ');
else if(TEST!=0)
assert(getchar()=='n');
assert(1<=a && a<=100000);
cnt[a%2]++;
cnt2[a]++;
}
int ans=0;
for(int i=0; i<2; i++)
ans+=cnt[i]*(cnt[i]-1)/2;
for(auto& it: cnt2)
ans-=it.second*(it.second-1)/2;
printf("%dn", ans);
}
assert(getchar()==EOF);
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 *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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