Recognize the Three Valid Capitalization Patterns

Recognize the Three Valid Capitalization Patterns

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return whether word uses one of three patterns: all uppercase letters, all lowercase letters, or only its first letter uppercase. Input contains English letters only. ```cpp class Solution { public: bool detectCapitalUse(string word); }; ``` ### Examples **Example 1:** ```text word = "River" Output: true Explanation: Only the first character is uppercase. ``` **Example 2:** ```text word = "riVer" Output: false Explanation: A later uppercase character violates all three patterns. ``` ### Constraints - The word contains 1..100 characters; each is an English uppercase or lowercase letter. ### Clarifying Questions Check the position of a lone uppercase letter as well as its count. ```hint Read the boundary condition Can the three permitted patterns be expressed using one uppercase count? ``` ### Contract considerations Check the position of a lone uppercase letter as well as its count.
Google logo
Google
Jul 8, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return whether word uses one of three patterns: all uppercase letters, all lowercase letters, or only its first letter uppercase. Input contains English letters only.

class Solution {
public:
    bool detectCapitalUse(string word);
};

Examples

Example 1:

word = "River"
Output: true
Explanation: Only the first character is uppercase.

Example 2:

word = "riVer"
Output: false
Explanation: A later uppercase character violates all three patterns.

Constraints

  • The word contains 1..100 characters; each is an English uppercase or lowercase letter.

Clarifying Questions Guidance

Check the position of a lone uppercase letter as well as its count.

Contract considerations

Check the position of a lone uppercase letter as well as its count.