It will give TLE in O(n*n). try better approach


#1
int Solution::seats(string A) {
    int n = A.length();
    int total=0;
    for(char a:A)
        if(a=='x')
            total++;
    if(total==0) return 0;
    vector<pair<int,int>> dp(n);
    int left =0;
    for(int i=0;i<n;i++)
    {
        if(A[i]=='x')
        {
            dp[i] = {left,total-left-1};
            left++;
        }
    }
    int ans =0;
    for(int i=0;i<n;i++)
    {
        if(A[i]=='x' && dp[i].first>dp[i].second)
        {
            A[i] ='.';
            while(A[i-1]=='.')
            {
                ans++;
                i--;
            }
            A[i]= 'x';
        }
    }
    
    for(int i=n-1;i>=0;i--)
    {
        if(A[i]=='x' && dp[i].first<dp[i].second)
        {
            A[i]= '.';
            while(A[i+1]=='.')
            {
                ans++;
                i++;
            }
            A[i] = 'x';
        }
    }
    return ans%10000003;
}