Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Microsoft - MaxEmployeeAttendence (R repititions - 1st step towards DP.)
//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>> availability; int NumberOfEmployeesAvailable(vector<int>& selected_days) { unordered_set<int> selected_days_set; for (auto i : selected_days) selected_days_set.insert (i); int unique_employees = 0; for (int employee = 0; employee < availability.size(); employee ++) { for (int day : availability[employee]) { if (selected_days_set.count(day) != 0) { unique_employees ++; break; } } } return unique_employees; } int MaxEmployeeAttendence (int current_day, int repititions_left, vector<int> selected_days) { if (repititions_left == 0) { return NumberOfEmployeesAvailable (selected_days); } 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 vector<int> new_selected_days = selected_days; new_selected_days.push_back(current_day); result = max (result, MaxEmployeeAttendence(current_day-1, repititions_left-1, new_selected_days)); // don't take the current day result = max (result, MaxEmployeeAttendence(current_day-1, repititions_left, selected_days)); 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) { availability = _availability; return MaxEmployeeAttendence (total_days-1, repititions, {}); } 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
MINVEST
32bit
pm zn moer 2.0
homework
runtime template mode processor
Extended Euclidean Algorithm
poker.hpp
HeapSort
26 და 28 მარტს დამუშავებული
StrTok