CANDYBOX - EDITORIAL

PROBLEM LINK:

Contest

Setter: debrc

Tester: dustu_947 , mishra_roshan

Editorialist: debrc

DIFFICULTY:

Cakewalk

PREREQUISITES:

Basic observations.

PROBLEM:

Given N number of boxes with candies, find the number of boxes which he can equally distribute among his three brothers.

EXPLANATION

Jon can only equally distribute those boxes, where the numbers of candies are equal to a multiple of 3. So, count the number of boxes whose number of candies are multiples of 3.

TIME COMPLEXITY

Time complexity is O(N) to check N number of boxes (ignoring complexity of modulus operator).

SOLUTIONS:

Setter's Solution
C++
#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    int n,cnt=0;
	    cin>>n;
	    while(n--)
	    {
	        int a;
	        cin>>a;
	        if(a%3==0)
	            cnt++;
	    }
	    cout<<cnt<<endl;
	}
	return 0;
}
Python
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    count=0
    for i in a:
        if i%3==0:
            count+=1
    print(count)
Tester's Solution
#include <iostream>
using namespace std;

int main() {
	int T;
	std::cin >> T;
	while(T--)
	{
	    int N;
	    cin>>N;
	    int A[N];
	    for(int i=0;i<N;i++)
	        cin>>A[i];
	   int count=0;
	    for(int i=0;i<N;i++)
	    {
	        if(A[i]%3==0)
	            count++;
	    }
	    std::cout << count << std::endl;
	}
	return 0;
}

Feel free to Share your approach.
Suggestions are welcome.