Devu and friendship testing Codechef Solution

Hello Programmers In this post, you will know how to solve the Devu and friendship testing Codechef Solution.

Ezoicreport this adDevu and friendship testing Codechef Solution
Devu and friendship testing Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Ezoicreport this adProblem

Devu has n weird friends. Its his birthday today, so they thought that this is the best occasion for testing their friendship with him. They put up conditions before Devu that they will break the friendship unless he gives them a grand party on their chosen day. Formally, ith friend will break his friendship if he does not receive a grand party on dith day.

Devu despite being as rich as Gatsby, is quite frugal and can give at most one grand party daily. Also, he wants to invite only one person in a party. So he just wonders what is the maximum number of friendships he can save. Please help Devu in this tough task !!

Input

  • The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
  • First line will contain a single integer denoting n.
  • Second line will contain n space separated integers where ith integer corresponds to the day dith as given in the problem.

Output

Print a single line corresponding to the answer of the problem.

Constraints

  • 1 ≤ T ≤ 104
  • 1 ≤ n ≤ 50
  • 1 ≤ di ≤ 100

Sample Input 1 

2
2
3 2
2
1 1

Sample Output 1 

2
1

Explanation

Example case 1. Devu can give party to second friend on day 2 and first friend on day 3, so he can save both his friendships.

Example case 2. Both the friends want a party on day 1, and as the Devu can not afford more than one party a day, so he can save only one of the friendships, so answer is 1.

Devu and friendship testing CodeChef Solutions in JAVA

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
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		   int n=sc.nextInt();
		   int count=n;
		   int arr[]=new int[n];
		   for(int i=0;i<n;i++)
		   {
		      arr[i]=sc.nextInt();
		   }
		   Arrays.sort(arr);
		   for(int i=0;i<n-1;i++)
		   {
		      if(arr[i]==arr[i+1])
		      count--;
		   }
		   System.out.println(count);
		}
	}
}
Ezoicreport this ad

Devu and friendship testing CodeChef Solutions in CPP

#include <iostream>
using namespace std;
#include<stdlib.h>
#include<string.h>
#include<bits/stdc++.h>
void solve()
{
      int n;
      cin >> n;
      int H[101]={0};
      for(int i=0;i<n;i++){
            int x;
            cin >> x;
            H[x]++;
      }
      int ct=0;
      for(int i=0;i<=100;i++){
            if(H[i]>0){
                  ct++;
            }
      }
      cout << ct << endl;
}
int main()
{
      int t;
      cin>>t;
      while(t--){
            solve();
      }
}

Devu and friendship testing CodeChef Solutions in Python

t = int(input())
for i in range(t):
    n = int(input())
    days = list(map(int,input().split()))
    s = set(days)
    print(len(s))
    

Disclaimer: The above Problem (Devu and friendship testing) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Box of Chocolates Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad