Keyboard Row

Problem Id: 500 Difficulty: Easy


Intuition

Solution


class Solution:
    def in_one_line(self, rows, word):
        word = word.lower()
        if not word:
            return True
        c = word[0]
        for r in rows:
            if c in r:
                break
        for c in word:
            if c not in r:
                return False
        return True

    def findWords(self, words: List[str]) -> List[str]:
        rows = [
            "qwertyuiop",
            "asdfghjkl",
            "zxcvbnm"
        ]
        ans = []
        for word in words:
            if self.in_one_line(rows, word):
                ans.append(word)
        return ans