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 Bob’s confusion problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Bob’s confusion problem solution You are given a 3 x 3 grid. Each number in the grid is represented by Cij where (i,j) denotes the square at the ith row from the top and jth column from the left.
 
Bob gets confused. According to him, there are six integers a1, a2, a3, b1, b2, b3 whose values are fixed and the number written in the square (i,j) is equal to ai + bj. You are required to determine whether Bob is correct or not.
 
HackerEarth Bob's confusion problem solution

 

 

HackerEarth Bob’s confusion problem solution.

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

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define fix fixed<<setprecision(10)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define FastIO ios_base::sync_with_stdio(0),cin.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

void solve(){
int a[5],b[5],c[5][5];
rep(i,1,3) rep(j,1,3) cin>>c[i][j];
a[1]=0;
b[1]=c[1][1];
b[2]=c[1][2];
b[3]=c[1][3];
a[2]=c[2][2]-b[2];
a[3]=c[3][3]-b[3];
rep(i,1,3) rep(j,1,3){
if(a[i]+b[j]!=c[i][j]){
cout<<"NOn";
return;
}
}
cout<<"YESn";
}

signed main(){
FastIO;
int t;
cin>>t;
while(t--) solve();
return 0;
}
 

Second solution

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e5 + 14;
int n, c[3][3];

int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
for (auto &i : c)
for (int &j : i)
cin >> j;
bool ok = true;
for (int i = 1; i < 3; ++i)
for (int j = 1; j < 3; ++j)
ok &= c[i][j] == c[0][j] + c[i][0] - c[0][0];
cout << (ok ? "YESn" : "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 *

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