Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • 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
Programmingoneonone

HackerEarth 2 Fast 2 Furious problem solution

YASH PAL, 31 July 2024
In this HackerEarth 2, Fast 2 Furious problem solution Dom and Brian were trying to evade the truck drivers of Verone’s gang. They were too fast, too furious for them, and could get away from the truck drivers easily. They decided to race with each other, and divided the city into N checkpoints for the same. Mia was monitoring Dom and Brian throughout the race and she noted down their speeds at every checkpoint.
Roman was jobless, as usual, and told Mia that Dom would definitely have the maximum change in speed between any two consecutive checkpoints. Mia disagreed with him and challenged him that Brian would have a maximum change in speed.
Help Mia and Roman to find out who has the maximum change in speed between any two consecutive checkpoints – Dom or Brian.
Note: Both negative and positive changes have to be considered. Hence, the absolute value of maximum change in speed is to be considered.
HackerEarth 2 Fast 2 Furious problem solution

HackerEarth 2 Fast 2 Furious problem solution.

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

ll a[1000007];

int main() {
int n;
cin>>n;
assert(n>=2 && n<=1000000);
for(int i=0;i<n;i++) {
cin>>a[i];
assert(a[i] >= -1000000000 && a[i] <= 1000000000);
}
ll ret1 = -1;
for(int i=0;i<n-1;i++) ret1=max(ret1,abs(a[i]-a[i+1]));
for(int i=0;i<n;i++) {
cin>>a[i];
assert(a[i] >= -1000000000 && a[i] <= 1000000000);
}
ll ret2 = -1;
for(int i=0;i<n-1;i++) ret2=max(ret2,abs(a[i]-a[i+1]));
if(ret1 > ret2) cout << "Domn";
else if(ret1 < ret2) cout << "Briann";
else cout<<"Tien";
cout<<max(ret1,ret2)<<"n";
}

Second solution

#include <iostream>
#include <cassert>
using namespace std;


int main()
{
int n, D=0, B=0, prev, cur;
cin>>n;
assert(n>=2 && n<=1000000);
cin>>prev;
assert(abs(prev) <= (int)1e9);
for (int i=1; i<n; i++) {
cin>>cur;
assert(abs(cur) <= (int)1e9);
D = max(D, abs(cur-prev));
prev = cur;
}

cin>>prev;
assert(abs(prev) <= (int)1e9);
for (int i=1; i<n; i++) {
cin>>cur;
assert(abs(cur) <= (int)1e9);
B = max(B, abs(cur-prev));
prev = cur;
}

if (D==B){
cout<<"Tie"<<endl<<D;
}
else if (D>B) {
cout<<"Dom"<<endl<<D;
}
else {
cout<<"Brian"<<endl<<B;
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

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