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 << "Dom\n";
  else if(ret1 < ret2) cout << "Brian\n";
  else cout<<"Tie\n";
  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;
}