Check if uppercase characters in a string are used correctly or not

Check if uppercase characters in a string are used correctly or not
Given a string S consisting of uppercase and lowercase letters, the task is to check if uppercase characters are used correctly in the given string or not. Correct usage of uppercase characters are as follows:
All characters in the string are in uppercase. For example, “GEEKS”.
None of the characters are in uppercase. For example, “geeks”.
Only the first character is in uppercase. For example, “Geeks”.
Examples:

Input: S = “Geeks”Output: YesExplanation: Only the first character of the string is in uppercase and all the remaining characters are in lowercase.
Input: S = “GeeksForGeeks”Output: No

Approach: Follow the steps below to solve the problem:Check if the first character of the string is in uppercase or not. If found to be true, iterate over the remaining characters.
If all the remaining characters are in uppercase, print “Yes”. Otherwise, if any of the remaining characters are in uppercase, then print “NO”.
If the first character is not in uppercase, then check if all the remaining characters are in lowercase or not. If found to be true, then print “YES”. Otherwise, print “NO”.
Below is the implementation of the above approach:

C++

  
#include
using namespace std;
  

bool isLower(char c)
{
  
    return c >= ‘a’ and c = ‘A’ and c 1)
            return false;
  
        
        
        while (S[i] && isLower(S[i]))
            ++i;
        return i == N ? true : false;
    }
}
  

void detectUppercaseUse(string S)
{
    
    
    bool check = detectUppercaseUseUtil(S);
  
    
    if (check)
        cout