Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
933 views
in Online Assessments by Expert (111,330 points) | 933 views

3 Answers

0 like 0 dislike
Best answer

These are the only two coding questions in the online assessment : 

 

  1. Given two strings str1 and str2. We say that str2 divides str1 if it's possible to concatenate multiple str2 to get str1. For example, ab divides abab. if str2 does not divide str1, return -1. Otherwise, return the smallest string str3 such that str3 divides both str1 and str2.
  2. Given an array of scores, and an integer k. Player with the same score will have the same rank, and the rank of the player is "the number of players with higher score" + 1. For instance, given scores = [10, 20, 20, 40], the corresponding rank is [4, 2, 2, 1]. Only players with a rank <= k can qualify for the next round. Return the number of player that qualify for the next round.
by Expert (111,330 points)
0 like 0 dislike
by Expert (111,330 points)
0 like 0 dislike

problem 2 can be solved like this:->

 

void solve() {

 

int n; cin >> n;
vector<int>p(n);
fo(i, n) {
    cin >> p[i];
}
int k; cin >> k;

sort(p.begin(), p.end(), greater<int>());

map<int, int>mp;
int rank = 1;

for (auto x : p) {

    if (!mp.count(x))
        mp[x] = rank;
    rank++;
}
int count = 0;
for (auto x : p) {
    if (mp[x] <= k)
        count++;
}

cout << count << endl;

 

}

by Expert (111,330 points)