Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Microsoft - MaxEmployeeAttendence (R repititions - 1st step towards DP solution)
//g++ 7.4.0 // https://leetcode.com/discuss/interview-experience/1930164/Microsoft-or-SDE2-or-Hyderabad-or-April-2022-Reject #include <bits/stdc++.h> using namespace std; vector<vector<int>> possible_attendants_at_day; int MaxEmployeeAttendence (int current_day, int repititions_left, unordered_set<int> employees) { if (repititions_left == 0) return employees.size(); if (current_day < 0) return 0; // There are no more days & we haven't organised the course for required `repititions`. int result = 0; // take the current day unordered_set<int> new_employees_set = employees; for (int employee : possible_attendants_at_day[current_day]) { new_employees_set.insert (employee); } result = max (result, MaxEmployeeAttendence(current_day-1, repititions_left-1, new_employees_set)); // don't take the current day result = max (result, MaxEmployeeAttendence(current_day-1, repititions_left, employees)); return result; } /* * availability[i] - list of days on which ith employee will be available to take the training. [0 <= availability[i][j] < D] * * total_days (D) - total number of days in which the training can be conducted. * * repititions (R) - number of times the training will be repeated in 'total_days' duration. * **/ int MaxEmployeeAttendence (vector<vector<int>>& availability, int total_days, int repititions) { possible_attendants_at_day.resize(total_days, {}); for (int employee = 0; employee < availability.size(); employee ++) { for (int day : availability[employee]) { possible_attendants_at_day [day].push_back(employee); } } unordered_set<int> employee_set; return MaxEmployeeAttendence (total_days-1, repititions, employee_set); } int main() { vector<vector<int>> availability = { {0, 3, 9}, {4}, {1, 4}, {3, 2}, {3, 4}, {7} }; cout << MaxEmployeeAttendence (availability, 10, 2) << endl; return 0; }
run
|
edit
|
history
|
help
0
c2p
decode
Test
Polyrmophism
member initial list
SayHi
Op&&^Overload
code
Eratosfen final
Microsoft - MaxEmployeeAttendence (R repititions - Optimised DP)