Everyone who is involved with HackerEarth in what so ever form knows who Little Kuldeep is. He's not so little, but he's called that. (No one knows why!) He's pretty efficient at organizing, mentoring, managing various hiring challenges, contests happening on HackerEarth all the time. But age has caught up with him, finally. He's turned into little, old Kuldeep from little Kuldeep.
Earlier, he could've handled multiple contests like a piece of cake, but it is not possible for him now. In the present scenario, he needs other people to moderate contests, because he's busy moderating some other contest which is happening at the same time.
Given the timings of the contests happening, can you check and tell little, old Kuldeep if he would need a moderator to help him out, or not?
Example:
Input: m = 2, str = {"11:00-13:30", "13:00-13:45"}
Output: Will need a moderator!
Approach
C++
#include <bits/stdc++.h>using namespace std;void littleContest(int m, vector<string> &str){vector<pair<double, double>> v;for (int j = 0; j < m; j++){string s = str[j];string start, end;int i = 0;int n = s.size();while (s[i] != '-'){if (s[i] == ':')start += '.';elsestart += s[i];i++;}i++;while (i < n){if (s[i] == ':')end += '.';elseend += s[i];i++;}stringstream str1(start);double x = 0.0;str1 >> x;stringstream str2(end);double y = 0.0;str2 >> y;v.push_back({x, y});}sort(v.begin(), v.end());int flag = 0;for (int i = 0; i < v.size() - 1; i++){if (v[i].second > v[i + 1].first){flag = 1;break;}}if (flag == 0)cout << "Who needs a moderator?\n";elsecout << "Will need a moderator!\n";}int main(){int m = 2;vector<string> str = {"11:00-13:30", "13:00-13:45"};littleContest(m, str);return 0;}
No comments:
Post a Comment