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)
Attention reader! Don’t stop learning now. Join the First-Step-to-DSA Course for Class 9 to 12 students , specifically designed to introduce data structures and algorithms to the class 9 to 12 students