Yash Kshatriya A Thinkschool
Yash Kshatriya A Thinkschool
Exam set : A
Location : Baner Pune Maharashtra
language : C++
code:
stack<char>st;
int n=s.size();
for(int i=0;i<n;i++){
}else{
return false;
}
}
}
if(st.size()==0){
return true;
}
return false;
}
approach:
question no 2 : find the max sum sub array -> (kadnes algorithm)
code :
int maxSum(vector<int>&arr){
int n=arr.size();
int sum_max=INT_MIN;
int total=0;
int min_element=INT_MAX;
for(int i=0;i<n;i++){
min_element=min(min_element,arr[i]);
int total=total+arr[i];
if(total<0)
total=0;
}
sum_max=max(sum_max,total);
}
if(max_sum==INT_MIN){
return min_element;
}
return max_sum;
}
Approach :
question no 3 : find the names and the prize money of top three players
problem understanding : I will be given a number of players and the points they
scored in respective games . Then according to the total number of points
that player has scored in tournament i have to decide the ranking
of top 3 players and allocate prizes accordingly.
code :
#include<bits/stdc++.h>
using name space std;
int main(){
int n;
cin>>n;
vector<pair<int,string>>players;
vector<int>prize(3);
map<string,int>mp;
for(int i=0;i<n;i++){
string name;
int p;
cin>>name>>p;
mp[name]=mp[name]+p;
}
for (auto i mp){
players.push_back({i.second,i.first});
}
for(int i=0;i<3;i++){
cin>>prize[i];
}
sort(players.rbegin(),players.rend());
for(int i=0;i<3;i++){
cout<<players[i].second<<endl;;
}
for(int i=0;i<3;i++){
cout<<prize[i]<<endl;
}
return 0;
}
Thinking -> if the problem also contains the case where the platyers can have a tie
in points then we can also maintion a number of different games played
by each player and then we can give a prize to a player having more
points in less games ;