Complete the Syllabus

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 nint a[])
{
    map<intstringmp;
    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 = 0i < 7i++)
    {

        sum += a[i];
    }
    if (n % sum == 0)
        n = sum;
    else
        n = n % sum;
    int ans;
    for (int i = 0i < 7i++)
    {
        n = n - a[i];
        if (n <= 0)
        {
            ans = i;
            break;
        }
    }
    return mp[ans + 1];
}
int main()
{

    int n = 2;
    int a[7] = {1100000};

    cout << completeSyllabus(na<< "\n";

    return 0;
}


No comments:

Post a Comment