The "Valid Word" interview question is a string validation task where you are given a word and must check if it meets several criteria to be considered "valid." Typical constraints include a minimum length (e.g., at least 3 characters), containing only alphanumeric characters, and having at least one vowel and at least one consonant.
Companies like Microsoft and Amazon use the "Valid Word" coding problem in early interview stages to verify basic string manipulation skills. It tests your ability to iterate through a string, handle case sensitivity, and manage multiple boolean flags or conditions efficiently. It is a straightforward test of clean coding practices.
The primary pattern is a "Linear String Scan." You iterate through each character of the word exactly once. During this scan, you check if each character is a digit, a vowel, or a consonant. You maintain boolean flags like hasVowel and hasConsonant and ensure no invalid characters (like symbols or spaces) are encountered.
Word: "b3App"
hasConsonant = true.hasVowel = true.hasVowel and hasConsonant are both true, and no invalid characters were found.A common mistake is not handling both uppercase and lowercase letters when checking for vowels. Another is failing to verify that the word contains only alphanumeric characters, often forgetting to return false immediately if a special character like @ or ! is found. Candidates also sometimes misclassify 'y' or digits as vowels/consonants.
When solving the "Valid Word" coding problem, define a set or a string containing all vowels ("aeiouAEIOU") for quick lookups. This is cleaner than writing a long if statement with ten different OR conditions and makes your code more readable.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Detect Capital | Easy | Solve | |
| Score of a String | Easy | Solve | |
| Find the Original Typed String I | Easy | Solve | |
| Delete Characters to Make Fancy String | Easy | Solve | |
| Length of Last Word | Easy | Solve |