Ninja technique🥷 to ACE DSA Interviews.
struct meeting
{
int start;
int end;
int pos;
};
bool comparator(struct meeting m1, meeting m2)
{
if (m1.end < m2.end)
return true;
else if (m1.end > m2.end)
return false;
else if (m1.pos < m2.pos)
return true;
return false;
}
void nMeetings(int s[], int e[], int n)
{
struct meeting meet[n];
for (int i = 0; i < n; i++)
{
meet[i].start = s[i];
meet[i].end = e[i];
meet[i].pos = i + 1;
}
sort(meet, meet + n, comparator);
vector<int> ans;
ans.push_back(meet[0].pos);
int limit = meet[0].end;
for (int i = 1; i < n; i++)
{
if (meet[i].start > limit)
{
limit = meet[i].end;
ans.push_back(meet[i].pos);
}
}
int l = ans.size();
for (int i = 0; i < l; i++)
{
cout << ans[i] << " ";
}
}