Check whether the string can be printed using same row of qwerty keypad
Given a string S, the task is to check whether the string can be typed using only a single row of the qwerty keyboard.
Input: S = “Dad”
Characters “D” and “a” are present in the same row of qwerty keypad. That is second Row.
Input: S = “Mom”
Characters “M” and “o” are not present in the same row of qwerty keypad.
Approach: The idea is to store the characters of the same row of the qwerty keypad into different hash-maps to check that all the characters of the string are from the same row.
Below is the implementation of the above approach:
Time Complexity: O(N)