O(n^2) NON DP SOLUTION


#1

int Solution::anytwo(string A) {
    int count=0;
    int flag =0;
    int x;
    for(int i = 0; i  <A.size();i++)
    {
        for(int j=(flag==0)?0:x;j<A.size();j++)
        {
            if(A[i]==A[j] && i!=j)
            {
                
                flag=1;
                x=j;
                count++;
                if(count==2)
                    return 1;
                
            }
        }
    }
    return 0;
}



#2

Hi
Your solution returns wrong answer for acccbba
Expected: 1 (because of ccc)
Actual: 0