Ash is preparing for his End semester exams and there are total K topics that he has to cover so that he can perform well in it. He has decided that he will study the topics sequentially. So, he is going to start on "MONDAY". Ash has got a very tight schedule and for each day of the week, he already knows how many topics will he be able to study on a particular day.
It is guaranteed that Ash will not skip any day and will follow the routine sincerely, Determine on which day of the week will he be able to complete all the topics. (1st day of the week is assumed to be MONDAY).
Example:
Input: n = 2, a {1,1,0,0,0,0,0}
Output: TUESDAY
Approach
C++
#include <bits/stdc++.h>using namespace std;string completeSyllabus(int n, int a[]){map<int, string> mp;mp[1] = "MONDAY";mp[2] = "TUESDAY";mp[3] = "WEDNESDAY";mp[4] = "THURSDAY";mp[5] = "FRIDAY";mp[6] = "SATURDAY";mp[7] = "SUNDAY";int sum = 0;for (int i = 0; i < 7; i++){sum += a[i];}if (n % sum == 0)n = sum;elsen = n % sum;int ans;for (int i = 0; i < 7; i++){n = n - a[i];if (n <= 0){ans = i;break;}}return mp[ans + 1];}int main(){int n = 2;int a[7] = {1, 1, 0, 0, 0, 0, 0};cout << completeSyllabus(n, a) << "\n";return 0;}
No comments:
Post a Comment