Attendance Codechef Solution

Hello Programmers In this post, you will know how to solve the Attendance Codechef Solution. The Problem Code: ATTND

Attendance Codechef Solution
Attendance 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.


Chef is teaching a cooking course. There are N students attending the course, numbered 1 through N.

Before each lesson, Chef has to take attendance, i.e. call out the names of students one by one and mark which students are present. Each student has a first name and a last name. In order to save time, Chef wants to call out only the first names of students. However, whenever there are multiple students with the same first name, Chef has to call out the full names (both first and last names) of all these students. For each student that does not share the first name with any other student, Chef may still call out only this student’s first name.

Help Chef decide, for each student, whether he will call out this student’s full name or only the first name.


  • The first line of the 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 a single integer N.
  • N lines follow. For each valid i, the ii-th of the following N lines contains two space-separated strings denoting the first and last name of student i.


For each test case, print N lines. For each valid ii, the i-th of these lines should describe how Chef calls out the i-th student’s name ― it should contain either the first name or the first and last name separated by a space.


  • 1≤T≤1001≤T≤100
  • 2≤N≤1002≤N≤100
  • all first and last names contain only lowercase English letters
  • the lengths of all first and last names are between 1 and 10 inclusive


Sample Input 1 

hasan jaddouh
farhod khakimiyon
kerim kochekov
hasan khateeb

Sample Output 1 

hasan jaddouh
hasan khateeb

Attendance CodeChef Solution in JAVA

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(;
		int T = sc.nextInt();
		for (int tc = 0; tc < T; tc++) {
			int N = sc.nextInt();
			String[] firstNames = new String[N];
			String[] lastNames = new String[N];
			for (int i = 0; i < N; i++) {
				firstNames[i] =;
				lastNames[i] =;
			System.out.print(solve(firstNames, lastNames));
	static String solve(String[] firstNames, String[] lastNames) {
		Map<String, Integer> firstNameToCount = new HashMap<>();
		for (String firstName : firstNames) {
			firstNameToCount.put(firstName, firstNameToCount.getOrDefault(firstName, 0) + 1);
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < firstNames.length; i++) {
			if (firstNameToCount.get(firstNames[i]) != 1) {
				result.append(" ").append(lastNames[i]);
		return result.toString();

Attendance CodeChef Solution in CPP

#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
      int n;
      string arr1[n];
      string arr2[n];
      for(int i=0;i<n;i++){
      for(int i=0;i<n;i++){
      int c=0;
          for(int j=0;j<n;j++){
                  cout<<arr1[i]<<" "<<arr2[i]<<endl;
	return 0;

Attendance CodeChef Solution in Python

t = int(input())
for i in range(t):
    n = int(input())
    d = []
    e = []
    for i in range(n):
        a, b = map(str, input().split())
    for i in range(n):
        if d.count(d[i])>1:
            print(d[i], e[i])

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

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: Attic Crossing Codechef Solution

Leave a Reply

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