116. Single Row Typists

A typing tutor wants to find words that can be typed using the letters of only one row of a standard keyboard. The rows are qwertyuiop, asdfghjkl and zxcvbnm. Upper and lower case letters count as the same key.

Given the list words, return a new list with the words whose letters all come from a single row, in the same order as in the input and written exactly as they appear there. If no word qualifies, return an empty list.

Example 1

Input:
words = ["dad","Poet","zoo","SASH"]
Output:
["dad","Poet","SASH"]
Explanation:

dad and SASH use only the middle row and Poet only the top row, while zoo mixes rows.

Example 2

Input:
words = ["Mnb","qaz"]
Output:
["Mnb"]
Explanation:

Mnb uses only the bottom row; qaz mixes the top, middle and bottom rows.

Constraints

1 ≤ words.length ≤ 1000

1 ≤ words[i].length ≤ 50

words[i] contains only English letters

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(total characters)
Space
O(1) extra

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…