Remarks - Pretty easy, finished everything in 15-20minutes - no flex : ) But seriously, no idea how this problemset will distinguish strong and weak candidates. Also hard to understand statements.
Answers to MCQ questions marked in the question itself. Let me know if something's wrong, didn't cross verify MCQs.
Problem 1
/*
* Complete the 'socialGraphs' function below.
*
* The function accepts INTEGER_ARRAY counts as parameter.
*/
void socialGraphs(vector counts) {
vector g[200020];
set tes;
for (int i = 0; i < counts.size(); ++i) {
g[counts[i]].push_back(i);
tes.insert(counts[i]);
}
vector> op;
for (auto xx: tes) {
int i = 0;
vector curs;
for (auto yy: g[xx]) {
curs.push_back(yy);
//cout << yy << " ";
++i;
if (i % xx == 0) {
i = 0;
//cout << "\n";
op.push_back(curs);
curs.clear();
}
}
}
sort(op.begin(), op.end());
for (int i = 0; i < op.size(); i++) {
for (auto xx: op[i]) cout << xx << " ";
cout << "\n";
}
}
Problem 2
/*
* Complete the 'minTime' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY processorTime
* 2. INTEGER_ARRAY taskTime
*/
int minTime(vector ptime, vector task) {
assert(ptime.size()*4 == task.size());
sort(ptime.begin(), ptime.end());
sort(task.begin(), task.end());
reverse(task.begin(), task.end());
int ans = 0;
for (int i = 0; i < (int)task.size(); i += 4) {
int j = i / 4;
ans = max(ans, task[i]+ptime[j]);
}
return ans;
}