Detect Capital

EasyStringssimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A word uses capital letters correctly when it matches one of these three shapes: - every letter is uppercase, like "USA"; - every letter is lowercase, like "leetcode"; - only the first letter is uppercase, like "Google". Given a string word made of English letters, return true if its capitalization is correct and false otherwise. A single letter of either case is always correct.

Examples

Input: word = "USA"
Output: true
All letters are uppercase.
Input: word = "FlaG"
Output: false
The final G is uppercase but the middle letters are not.

Constraints

  • 1 <= word.length <= 100
  • `word` consists of lowercase and uppercase English letters.
  • An empty string is never given.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems