Keyboard Row - Problem
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard.
Note that the strings are case-insensitive, both lowercased and uppercased of the same letter are treated as if they are at the same row.
In the American keyboard:
- The first row consists of the characters
"qwertyuiop" - The second row consists of the characters
"asdfghjkl" - The third row consists of the characters
"zxcvbnm"
Input & Output
Example 1 — Mixed Rows
$
Input:
words = ["Hello", "Alaska", "Dad", "Peace"]
›
Output:
["Alaska", "Dad"]
💡 Note:
"Alaska" uses only row 1 letters (a,s,k), "Dad" uses only row 2 letters (d,a). "Hello" and "Peace" use multiple rows.
Example 2 — Single Character
$
Input:
words = ["omk"]
›
Output:
[]
💡 Note:
"omk" contains 'o' (row 1), 'm' (row 3), 'k' (row 2) - uses all three keyboard rows, so not included.
Example 3 — Case Insensitive
$
Input:
words = ["adsdf", "sfd"]
›
Output:
["adsdf", "sfd"]
💡 Note:
Both words use only row 2 letters (a,d,s,f). Case doesn't matter as stated in problem.
Constraints
- 1 ≤ words.length ≤ 20
- 1 ≤ words[i].length ≤ 100
- words[i] consists of English letters.
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of words to check
2
Process
Check if each word uses only one keyboard row
3
Output
Return words that pass the single-row test
Key Takeaway
🎯 Key Insight: Pre-map letters to rows for instant validation rather than searching strings repeatedly
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code