I am trying to write a program that checks if characters of created word are in different length. for example word:
PAABBBMMMM
it should print Yes, because P was printed 1 time, A was printed 2 times, B was printed 3 Times, m was printed 4 times.
If the word was for e.g PAABB it should print no, because AA and BB is same length.
What I am doing wrong?
#include <iostream>
using namespace std;
 
bool checkChars(string s)
{
    int n = s.length();
    for (int i = 1; i < n; i++)
        if (s[i] != s[0])
            return false;
 
    return true;
}
 
// Driver code
int main()
{
    string s = "PAABBBMMMM";
    if (checkChars(s))
        cout << "Yes";
    else
        cout << "No";
 
    return 0;
}
 
    