Interview Questions/Coding/Team Eligibility Counter

Team Eligibility Counter

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Team Eligibility Counter

A campus has students who have already attended y_i contests. A student is eligible for a new team only if y_i + k <= 5, where k is the number of additional contests planned for this team. Every team must contain exactly three eligible students, and each student can be used in at most one team. For each batch, count how many full teams can be formed. The answer is not limited to 0 or 1; large batches may form many teams. Input Format: The first line contains t, the number of test cases. Each test case contains n and k, followed by n attendance counts. Output Format: For each test case, print the number of full teams.

Examples

Example 1
Input:
1
6 1
0 1 2 3 4 5
Output:
1

Explanation: Students with counts 0, 1, 2, 3, and 4 remain eligible because adding 1 keeps them at 5 or below. The student with count 5 is not eligible. Five eligible students make one full team, with two eligible students left over.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp