Problem 15

2 comments on “Problem 15”


  • Prajwal

    #include
    #include
    #include
    #include

    using namespace std;

    int alternate(string s) {
    // vector chars; // Store unique characters from the string
    // for (char c : s) {
    // if (find(chars.begin(), chars.end(), c) == chars.end()) {
    // chars.push_back(c);
    // }
    // }
    set st(s.begin(), s.end());
    vector chars(st.begin(), st.end());

    int maxLength = 0;
    int n = chars.size();
    for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
    char char1 = chars[i];
    char char2 = chars[j];
    string temp = s;
    temp.erase(remove_if(temp.begin(), temp.end(), [&](char c){
    return c!=char1 and c!=char2;
    }), temp.end());

    bool isAlternate = true;
    int length = temp.length();
    for (int k = 0; k > l;

    string s;
    cin >> s;

    int result = alternate(s);
    cout << result << endl;

    return 0;
    }


  • Pratik

    def alternate(s):
    maxnum = count = 0
    alp = list(set(s))
    for i in range(len(alp)):
    for j in range(i+1, len(alp)):
    l = [alp[i], alp[j]]
    if s.index(alp[i])<s.index(alp[j]):
    ind = 0
    else:
    ind = 1
    for char in s:
    if char in l:
    if char ==l[ind]:
    count += 1
    ind = ind^1
    else:
    count = 0
    break
    maxsum = max(maxsum,count)
    return maxsum