cant find my MAX01EVSWP c code mistake in march long challenge 2 2022

can someone help me why only 2 test cases passed in my code, and which test case I might be missing?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void stringsearcher(int, int, int, int, int);

void oddeven(int, char *);

void oddeven(int len, char str[])
{
    int ozeros, ezeros, eonce, oonce;

    ezeros = 0, ozeros = 0;
    eonce = 0, oonce = 0;

    for (int cntr2 = 0; cntr2 < len; cntr2++)
    {
        if (cntr2 % 2 != 0)
        {
            if (str[cntr2] == '0')
            {
                ezeros = ezeros + 1;
            }

            else
            {
                eonce = eonce + 1;
            }
        }
        else
        {
            if (str[cntr2] == '0')
            {
                ozeros = ozeros + 1;
            }

            else
            {
                oonce = oonce + 1;
            }
        }
    }
   
    stringsearcher(len, oonce, ozeros, eonce, ezeros);
}

void stringsearcher(int len, int oonce, int ozeros, int eonce, int ezeros)
{
    int cntr;
    int count = 0, count1 = 0;
    char *strmake = (char *)malloc((len + 1) * sizeof(char));

    for (cntr = 0; cntr < len; cntr++)
    {
        if (cntr % 2 == 0)
        {
            if (ozeros != 0)
            {
                strmake[cntr] = '0';

                ozeros--;
            }
            else
            {
                strmake[cntr] = '1';

                oonce--;
            }
        }
        else
        {
            if (eonce != 0)
            {
                strmake[cntr] = '1';

                eonce--;
            }
            else
            {
                strmake[cntr] = '0';

                ezeros--;
            }
        }
    }

    count1 = substring_count(strmake);

    printf("\n%s\n", strmake);

    printf("%d\n", count1);
}

int substring_count(char *string)
{
    int i, j, l1, l2;
    int count = 0;
    int found = 0;
    char substring[] = "01";
    l1 = strlen(string);
    l2 = strlen(substring);

    for (i = 0; i < l1 - l2 + 1; i++)
    {
        found = 1;
        for (j = 0; j < l2; j++)
        {
            if (string[i + j] != substring[j])
            {
                found = 0;
                break;
            }
        }

        if (found)
        {
            count++;
            i = i + l2 - 1;
        }
    }

    return count;
}

int main()
{
    int tst, len;

    scanf("%d", &tst);

    for (int cntr = 0; cntr < tst; cntr++)
    {

        scanf("%d", &len);

        char *str = (char *)malloc((len + 1) * sizeof(char));

        scanf("%s", str);

        oddeven(len, str);
    }
    return 0;
}

Hey @hello_vaibhav :wave: ,
Your code is failing for the test case
1
8
11111100
here correct answer is 2 but your code is printing 1.
You can go through my code for this problem maybe it’ll help you :slight_smile:

#include <iostream>
#include<bits/stdc++.h>
#include<deque>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<stdio.h>
#include<bitset>
#include<string>
#include<vector>
#include<unordered_map>
#include<queue>
#include<set>
#include<fstream>
#include<map>
#define int long long int
#define ld long double
#define pi 3.1415926535897932384626433832795028841971
#define MOD 1000000007
#define MOD1 998244353
#define print(vec) for (int i = 0; i < vec.size(); i++) cout << vec[i] << " "; cout << "\n";
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int inf = 1e18;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#ifdef __SIZEOF_INT128__
ostream& operator << (ostream &os, __int128 const& value) {
    static char buffer[64];
    int index = 0;
    __uint128_t T = (value < 0) ? (-(value + 1)) + __uint128_t(1) : value;
    if (value < 0)
        os << '-';
    else if (T == 0)
        return os << '0';
    for (; T > 0; ++index) {
        buffer[index] = static_cast<char>('0' + (T % 10));
        T /= 10;
    }
    while (index > 0)
        os << buffer[--index];
    return os;
}
istream& operator >> (istream& is, __int128& T) {
    static char buffer[64];
    is >> buffer;
    size_t len = strlen(buffer), index = 0;
    T = 0; int mul = 1;
    if (buffer[index] == '-')
        ++index, mul *= -1;
    for (; index < len; ++index)
        T = T * 10 + static_cast<int>(buffer[index] - '0');
    T *= mul;
    return is;
}
#endif
int add(long long a, long long b) {return ((a % MOD) + (b % MOD)) % MOD;}
int subtract(long long a, long long b) {return ((a % MOD) - (b % MOD)) % MOD;}
int mult(long long a, long long b) {return ((a % MOD) * (b % MOD)) % MOD;}
int add1(long long a, long long b) {return ((a % MOD1) + (b % MOD1)) % MOD1;}
int subtract1(long long a, long long b) {return ((a % MOD1) - (b % MOD1)) % MOD1;}
int mult1(long long a, long long b) {return ((a % MOD1) * (b % MOD1)) % MOD1;}
int expo(int a, int b, int mod) {
    int res = 1;
    while (b > 0)
    {   if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b = b >> 1;
    } return res;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int mminvprime(int a, int b) {
    return expo(a, b, b + 2);
}
int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        vector<vector<int>> par(2, vector<int>(2, 0));
        string s;
        cin >> s;
        for (int i = 0; i < n; ++i)
        {
            par[i % 2][(s[i] - '0') % 2]++;
        }
        string tmp;
        for (int i = 0; i + 1 < n; ++i)
        {
            if (par[i % 2][0] && par[(i + 1) % 2][1])
            {
                tmp.push_back('0');
                tmp.push_back('1');
                par[i % 2][0]--;
                par[(i + 1) % 2][1]--;
                i++;
            }
            else
            {
                if (par[i % 2][0])
                {
                    par[i % 2][0]--;
                    tmp.push_back('0');
                }
                else
                {
                    par[i % 2][1]--;
                    tmp.push_back('1');
                }
            }
        }
        n--;
        if (par[n % 2][0] > 0) tmp.push_back('0');
        else if (par[n % 2][1] > 0)tmp.push_back('1');
        int c = 0;
        for (int i = 0; i < tmp.size() - 1; ++i)
        {
            if (tmp[i] != tmp[i + 1] && tmp[i] == '0') c++;
        }
        cout << c << "\n";
    }
    return 0;
}