Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Microsoft - MaxEmployeeAttendence (R repititions - 1st step towards DP...
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 2.24 sec, absolute running time: 0.17 sec, cpu time: 0.01 sec, memory peak: 6 Mb, absolute service time: 2,52 sec
edit mode
|
history
|
discussion
5