Days of Our Lives | Practice | GeeksforGeeks

Given a month with arbitrary number of days, N, and an integer K representing the day with which it starts. ie- 1 for Monday, 2 for Tuesday and so on.  Find the number of times each day (Monday, Tuesday, ..., Sunday) appears in the month. 
 
Example 1:
Input:
N = 31 , K = 1
Output:
5 5 5 4 4 4 4 
Explanation: The month starts from Monday.
There will be 4 days of each day
(Sunday , Monday , etc) upto 28th of the
Month. Then, The successive 3 days will
have a extra day each. So, Monday, Tuesday
and Wednesday will have 5 days while the
others will have 4 days each.

Example 2:
Input:
N = 28, K = 5
Output:
5 5 5 4 4 4 4 
Explanation: Each day of the month will
have 4 days each and thus the Output.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function daysOfWeeks() which takes Integers N  and K as input and return a list of 7 integers indicating number of days in each day of the week.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 105
1 <= K <= 7
0
pawan16085 months ago
vector<int> v={N/7,N/7,N/7,N/7,N/7,N/7,N/7};
        N = N%7;
        int i = 0;
        while(N--)
        {
            int a = (K-1 + i)%7;
            v[a]++;
            i++;
        }
        return v;
0
Nandan9 months ago
Nandan
Wrong output in example-2https://uploads.disquscdn.c...
-1
Kamal Meena2 years ago
Kamal Meena
Python Solution Ex.Time:0.01https://ide.geeksforgeeks.o...
-1
Jaspal Singh2 years ago
Jaspal Singh
#include<bits stdc++.h="">#define int long long int using namespace std;    main(){     int t;cin>>t;    while(t--){   int n,k;cin>>n>>k;int arr[7]; for(int i=0;i<7;i++)     arr[i]=0;    int tmp=n/7;     for(int i=0;i<7;i++)      arr[i]=tmp;          n=n-tmp*7;        k=k-1;    if(n!=0)     while(n!=0)     {         arr[k++]+=1;          if(k==7)             k=0;            n--;     }     for(int i=0;i<7;i++)      cout<<arr[i]<<" ";="" cout<<endl;="" }="" }="">
-1
vinayak lakhotiya4 years ago
vinayak lakhotiya
Simple https://ide.geeksforgeeks.o... https://uploads.disquscdn.c...
-1
juggernaut4 years ago
juggernaut
use long instead
-1
El Mayor Misterio4 years ago
El Mayor Misterio
what's wrong with this code..
https://ide.geeksforgeeks.o...
what does this mean:Runtime Error:Runtime ErrorException in thread "main" java.util.InputMismatchException: For input string: "696407850067"at java.util.Scanner.nextInt(Scanner.java:2123)at java.util.Scanner.nextInt(Scanner.java:2076)at GFG.main(File.java:13)
-1
Vincenzo4 years ago
Vincenzo
Solvable in O(k)
Execution Time:0.03Is there a better way to deal with the remainder?https://ide.geeksforgeeks.o...
-1
Palash Bhatnagar4 years ago
Palash Bhatnagar
https://ide.geeksforgeeks.o... I'm having Time Exceed Error. what's wrong with my code
-1
ad!tya4 years ago
ad!tya
https://ide.geeksforgeeks.o...i have tested this code for every boundary cases and it gave correct answer but submition is giving run time error (Abort signal from abort(3) (SIGABRT)) what is the reason?
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.