Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Count the Holidays CodeChef Solution

Problem – Count the Holidays CodeChef Solution

A particular month has 30 days, numbered from 1 to 30.

Day 1 is a Monday, and the usual 7-day week is followed (so day 2 is Tuesday, day 3 is Wednesday, and so on).

Every Saturday and Sunday is a holiday. There are N festival days, which are also holidays. Note that it is possible for a festival day to occur on a Saturday or Sunday.

You are given the dates of the festivals. Determine the total number of holidays in this month.

Input Format

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains an integer N denoting the number of festival days.
  • The second line of each test case contains N distinct space-separated integers A1​,A2​,…AN​, denoting the festival days. Note that the Ai​ are not necessarily given in sorted order.

Output Format

For each test case, output a new line containing the total number of holidays.

Constraints

  • 1≤T≤1000
  • 1≤N≤30
  • 1≤Ai​≤30
  • All the Ai​ are distinct

Sample 1:

Input:
3
2
5 7
3
23 1 6
1
13
Output:
9
10
8

Explanation:

Test Case 1: Days 6,13,20 and 27 are Saturdays, and days 7,14,21,28 are Sundays. The festivals fall on day 5 and day 7, but day 7 is already a Sunday. This gives us 9 holidays in total — days 5,6,7,13,14,20,21,27,28.

Test Case 2: Days 6,13,20 and 27 are Saturdays, and days 7,14,21,28 are Sundays. The festivals fall on day 1, day 6, and day 23. This gives us 10 holidays in total — days 1,6,7,13,14,20,21,23,27,28.

Test Case 3: Days 6,13,20 and 27 are Saturdays, and days 7,14,21,28 are Sundays. The only festival is on day 13, which is already a holiday. This gives us 8 holidays in total — days 6,7,13,14,20,21,27,28.

Count the Holidays CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,count=0;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++)
	    cin>>a[i];
	    for(int i=0;i<n;i++){
            if (a[i]%7==0 || (a[i]+1)%7==0){
                count++;
            }
        }
        cout<<8+n-count<<endl;
	}
	return 0;
}

Count the Holidays CodeChef Solution in PyPy3

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    l = [6,7,13,14,20,21,27,28]
    for i in a:
        if i not in l:
                l.append(i)
    print(len(l))
        

        
    
    

Count the Holidays CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
		    int h=8;
		    int f=sc.nextInt();
		    for (int j=0;j<f;j++)
		    {
		        int k=sc.nextInt();
		        if(k!=6&&k!=7&&k!=13&&k!=14&&k!=20&&k!=21&&k!=27&&k!=28)
		        {
		        h++;
		        }
		       
		    }
		     System.out.println(h);
		     
		}
		
	}
}
Count the Holidays CodeChef Solution Review:

In our experience, we suggest you solve this Count the Holidays CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Count the Holidays CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Count the Holidays CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *