We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Other Concepts
- Attending Workshops
- Discussions
Attending Workshops
Attending Workshops
Sort by
recency
|
181 Discussions
|
Please Login in order to post a comment
A small recursive solution:
//Define the structs Workshops and Available_Workshops. //Implement the functions initialize and CalculateMaxWorkshops struct Workshop { int start_time; int duration; int end_time; };
bool operator<(const Workshop & lhs, const Workshop & rhs) { return (lhs.end_time < rhs.end_time); }
struct Available_Workshops { std::vector arr; int n; };
Available_Workshops *initialize(int start_time[], int duration[], int n) { Available_Workshops *obj;
}
int CalculateMaxWorkshops(Available_Workshops *ptr) { int curr_end; int max;
}
This is an Interval Scheduling Problem
The greedy algorithm given on that page here is a simple and computationally efficient solution to this problem.
It took me some time to figure it out. But this eventually worked and passed all the test cases.