We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;classDifference{private:vector<int>elements;public:intmaximumDifference;// Add your code hereDifference(vector<int>elements){this->elements=elements;}voidcomputeDifference(){intmax=0;for(inti=0;i<elements.size();i++){for(intj=0;j<elements.size();j++){if(i<=j){continue;}max=std::max(max,abs(elements[i]-elements[j]));}}this->maximumDifference=max;}};// End of Difference classintmain(){intN;cin>>N;vector<int>a;for(inti=0;i<N;i++){inte;cin>>e;a.push_back(e);}Differenced(a);d.computeDifference();cout<<d.maximumDifference;return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 14: Scope
You are viewing a single comment's thread. Return to all comments →
C++ Solution