COMPILER problem having issues, WA

Having issues in debugging the code. The test cases given in the problem are giving correct output but while submitting it is showing wrong answer. Please help.

below is the code:

#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        stack <char>  s;
        string input;
        cin >> input;
        ll count = 0, max = 0;
        for (auto x : input)
        {
            if (x == '<')
            {
                s.push(x);
                count++;
            }
            if (!s.empty() && x == '>')
            {
                if (s.top() == '<')
                {
                    s.pop();
                    count++;
                }
            }
            if (s.empty() && x == '>')
            {
                if (count > max)
                   max = count;
                break;
            }
        }
        cout << max << "\n";
    }
}

and I have also tried a different approach:

#include <bits/stdc++.h>
using namespace std;

int resultNum(string p)
{
    int cnt = 0;
    stack<char> st;
    for (auto x : p)
    {
        if (x == '<')
            st.push(x), cnt++;
        if (x == '>')
            st.pop(), cnt++;
        if (st.empty())
            return cnt;
    }
    return cnt;
}

int main()
{
   // INPUT;
    int t;
    cin >> t;

    while (t--)
    {
        string s, p = "";
        int count1 = 0, count2 = 0;
        cin >> s;
        for (auto x : s)
        {
            if (x == '<')
                count1++;
            else
                count2++;
            if (count2 > count1)
                break;
            p += x;
        }

        cout << resultNum(p) << "\n";
    }
}

Your first approach fails for this test input.

The second approach fails for this one:

1
<
2 Likes

https://www.codechef.com/viewsolution/32201406
please help me too.

what should be the output here?

For the second one? 0.

1 Like

This solution fails on the following test input:

1
<<>

(the answer should be 0).

2 Likes

https://www.codechef.com/viewsolution/32209321
Now what is wrong?

1
<><

(the answer should be 2).

2 Likes