https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050eda/0000000000119866
This a problem from kickstart 2019 Round B.
The test set1 works fine, but a TLE on testSet2, could any one resolve this 
issue? If any please do reply.
Thanks

#include <bits/stdc++.h>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
bool palindrome(string s)
{
    set<char> st(s.begin(), s.end());
    for (char ele : st)
        if (count(s.begin(), s.end(), ele) % 2 == 0)
            s.erase(remove(s.begin(), s.end(), ele), s.end());
    set<char> revised(s.begin(), s.end());
    if (revised.size() <= 1)
        return true;
    return false;
}
int main()
{
    int te;
    cin >> te;
    for (int i = 0; i < te; i++)
    {
        cout << "Case #" << i + 1 << ": ";
        long long n, q;
        cin >> n >> q;
        cout << q;
        string str = "";
        long long count = 0;
        cin >> str;
        for (long long j = 0; j < q; j++)
        {
            long long l, r;
            cin >> l >> r;
            if (palindrome(str.substr(l - 1, r - l + 1)))
                count++;
        }
        cout << count << endl;
    }
}


-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/3f1f9c69-6bc2-4e72-a197-6f5377770bfe%40googlegroups.com.

Reply via email to