Q:

What's the difference or error in following codes?

I had to find the minimum of an array. First I used stl and then I used simple method but in case of stl my code got rejected. Is it wrong? The problrm may be found here:
https://www.codechef.com/problems/CFMM
I executed both codes on the same online judge but STL one got rejected. 
int a_min = ar[0];
for(int i=1;i<6;i++)
            if(ar[i]<a_min)
                a_min = ar[i];
        cout<<a_min<<endl;

STL one :
int *a_min = min_element(ar,ar+5);
        cout<<*a_min<<endl;

The full code is here:
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t, n, a_min;
    string str;
    cin>>t;
    char check[6] = {'c','o','d','e','h','f'};
    while(t--){
        int ar[6] = {0};
        cin>>n;
        while(n--){
            cin>>str;
            for(int i=0;i<str.size();i++){
                for(int j=0;j<6;j++)
                    if(str[i] == check[j])
                        if(str[i] == check[j])
                            ar[j]++;
            }
        }
        ar[0] /= 2;
        ar[3] /= 2;
        a_min = ar[0];
        for(int i=1;i<6;i++)   //min code from here
            if(ar[i]<a_min)
                a_min = ar[i];
        cout<<a_min<<endl;    //cout<<*a_min<<endl; for stl one
    }
}

A:

You are using:
int *a_min = min_element(ar,ar+5);

You'll need to change it to:
int *a_min = min_element(ar,ar+6);

so that it checks for 6 elements of ar.
It seems logical to think you'll need to have pointer to last element of array as second argument to min_element but the format is min_element(first, last) where it iterates from first iterator to last excluding the last iterator.

