Problem
Count how many characters in text are uppercase English letters A–Z.
Implement count_uppercase(text).
Input
text: The text to inspect.
Output
Return the number of uppercase letters.
Constraints
0 ≤ length of text ≤ 10,000 (ASCII characters)
Examples
Input:
text = "Hello World"
Expected output:
expected = 2
Input:
std::string text = "Hello World";
Expected output:
long long expected = 2;
Input:
string text = "Hello World";
Expected output:
long expected = 2;
Explanation
H and W are uppercase: 2.
Input:
text = "no caps here!"
Expected output:
expected = 0
Input:
std::string text = "no caps here!";
Expected output:
long long expected = 0;
Input:
string text = "no caps here!";
Expected output:
long expected = 0;
Explanation
There are no uppercase letters: 0.
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
Scan the text once and notice only letters A through Z count.
Hint 2
Check each character’s case directly instead of comparing against words or splitting the string.
Hint 3
Remember lowercase letters, digits, spaces, and punctuation do not contribute.
Expected complexity
O(n) time, O(1) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.