Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of an American keyboard. The first row is "qwertyuiop", the second row is "asdfghjkl" and the third row is "zxcvbnm". Letters are case-insensitive, so "A" and "a" sit on the same row. Return the words in the order they appear in the input.
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of an American keyboard. The first row is "qwertyuiop", the second row is "asdfghjkl" and the third row is "zxcvbnm". Letters are case-insensitive, so "A" and "a" sit on the same row. Return the words in the order they appear in the input.
Example 1:
Input: {"words":["Hello","Alaska","Dad","Peace"]}
Output: ["Alaska","Dad"]
Constraints:
1≤words.length≤20
1≤words[i].length≤100
words[i] consists of English letters (both lowercase and uppercase).
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"words":["Hello","Alaska","Dad","Peace"]}
Tag every key with its row: q to p is the top row (0), a to l the middle row (1), z to m the bottom row (2). A word passes only if all its letters share one tag.