1st question
Q1 answer is too long dosent feel like a test question can someone confirm if this is the only method or was there any better and shorter to code method ;(
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>> seq = {{7,2,6,6,14},{14,12,23,14,17},{11,13,13,12,18},{11,12,11,50,9}};
vector<vector<int>> v (seq.size(), vector<int>(seq[0].size()));
for(int i=0; i<seq[0].size(); i++){
int temp = 0;
for(int j=0; j<seq.size(); j++){
temp = max(temp,seq[j][i]);
}
for(int j=0; j<seq.size(); j++){
if(seq[j][i]==temp){
v[j][i]=1;
}
}
}
// for(int i=0; i<seq.size(); i++){
// for(int j=0; j<seq[0].size(); j++){
// cout<<v[i][j]<<" ";
// }
// cout<<endl;
// }
// cout<<endl;
vector<vector<int>> pairs;
vector<int> temp_pair;
for(int i=0; i<v.size(); i++){
int temp = 0 ;
for(int j=0; j<v[0].size(); j++){
temp+=v[i][j];
}
temp_pair.push_back(temp);
temp_pair.push_back(i);
pairs.push_back(temp_pair);
temp_pair.clear();
}
sort(pairs.begin(),pairs.end());
reverse(pairs.begin(),pairs.end());
// for(int i=0; i<pairs.size(); i++){
// for(int j=0; j<2; j++){
// cout<<pairs[i][j]<<" ";
// }
// cout<<endl;
// }
int no_possible = 0 ;
int first_pair = pairs[0][0];
for(int i=0; i<pairs.size(); i++){
if(pairs[i][0]==first_pair){
no_possible++;
}
else{
break;
}
}
// cout<<first_pair<<endl;
vector<vector<int>> last_resort ;
for(int i=0; i<no_possible; i++){
int avg = 0 ;
for(int j=0; j<seq[0].size(); j++){
avg+=seq[pairs[i][1]][j];
}
avg /= seq[0].size();
pairs[i].push_back(avg);
reverse(pairs[i].begin(),pairs[i].end());
last_resort.push_back(pairs[i]);
}
sort(last_resort.begin(),last_resort.end());
reverse(last_resort.begin(),last_resort.end());
cout<<"number of highest elements "<<last_resort[0][2]<<" and average of that sequence "<<last_resort[0][0]<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
vector<vector<int>>v;
for(int i=0;i<m;i++){
vector<int>temp;
for(int j=0;j<n;j++){
int a;
cin>>a;
temp.push_back(a);
}
v.push_back(temp);
}
map<int,int>maximums;
for(int i=0;i<n;i++){
int temp=INT_MIN;
for(int j=0;j<m;j++){
temp=max(temp,v[j][i]);
}
maximums[temp]++;
}
map<int,map<int,int>>store;
vector<int>ids;
int maxsize=INT_MIN;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(maximums.find(v[i][j])!=maximums.end()){
store[i][v[i][j]]++;
}
}
if(static_cast<int>(store[i].size())>maxsize){
maxsize=store[i].size();
ids.clear();
ids.push_back(i);
}
else if(store[i].size()==maxsize){
ids.push_back(i);
}
}
vector<pair<int,int>>answer;
double average=INT_MIN;
for(int i=0;i<ids.size();i++){
double sum=0;
for(int j=0;j<v[ids[i]].size();j++){
sum+=v[ids[i]][j];
}
double temp=sum/v[ids[i]].size();
if(temp>average){
average=temp;
answer.clear();
answer.push_back({ids[i],store[ids[i]].size()});
}
else if(temp==average){
answer.push_back({ids[i],store[ids[i]].size()});
}
}
for(int i=0;i<answer.size();i++){
cout<<answer[i].first<<" "<<answer[i].second<<endl;
}
}
int n,m;cin>>n>>m;
int A[n][m];
unordered_map<int,int>s,mp;
int c = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cin>>A[i][j];
s[i] += A[i][j];
}
}
int maxi = -1;
for(int i = 0;i<m;i++){
maxi = -1;
for(int j = 0;j<n;j++)
maxi = max(maxi,A[j][i]);
for(int j = 0;j<n;j++){
if(A[j][i] == maxi)mp[j]++;
}
}
maxi = -1;
int sum = 0;
int ans = -1;
for(auto it:mp)maxi = max(maxi,it.ss);
int other = maxi;
for(int i = 0;i<n;i++){
if(mp[i] != maxi)continue;
if(sum < s[i]){
ans = i;
sum = s[i];
}
}
cout<<ans<<" "<<other<<endl;