Detect Capital - Problem
Detect Capital - String Pattern Recognition
You're a text editor developer implementing a smart capitalization checker! Your task is to determine if a word follows proper capitalization rules.
Valid Capitalization Patterns:
๐น All uppercase:
๐น All lowercase:
๐น Title case:
Goal: Return
Think of it like a grammar checker that validates proper noun formatting!
You're a text editor developer implementing a smart capitalization checker! Your task is to determine if a word follows proper capitalization rules.
Valid Capitalization Patterns:
๐น All uppercase:
"USA", "NASA"๐น All lowercase:
"hello", "world"๐น Title case:
"Google", "Apple"Goal: Return
true if the word follows one of these patterns, false otherwise.Think of it like a grammar checker that validates proper noun formatting!
Input & Output
example_1.py โ All Uppercase
$
Input:
word = "USA"
โบ
Output:
true
๐ก Note:
All letters are uppercase, which is one of the valid capitalization patterns.
example_2.py โ Title Case
$
Input:
word = "Google"
โบ
Output:
true
๐ก Note:
Only the first letter is uppercase and the rest are lowercase, forming valid title case.
example_3.py โ Invalid Mixed Case
$
Input:
word = "FlaG"
โบ
Output:
false
๐ก Note:
Mixed capitalization that doesn't follow any valid pattern - not all uppercase, not all lowercase, and not title case.
Constraints
- 1 โค word.length โค 100
- word consists of lowercase and uppercase English letters only
- No empty strings or special characters
Visualization
Tap to expand
Understanding the Visualization
1
Count the Uniforms
Count how many team members are wearing formal uniforms (uppercase letters)
2
Check the Captain
See if the team captain (first letter) is wearing a formal uniform
3
Determine Team Status
Valid teams: all formal, all casual, or captain formal with casual team
Key Takeaway
๐ฏ Key Insight: Only three valid patterns exist, and counting uppercase letters with first letter check covers all cases efficiently in O(n) time.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code