Keyboard Row

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.
In the American keyboard:
the first row consists of the characters
"qwertyuiop",the second row consists of the characters
"asdfghjkl", andthe third row consists of the characters
"zxcvbnm".
LeetCode Problem - 500
class Solution {
// Method to find words that can be typed using only one row of the keyboard
public String[] findWords(String[] words) {
// List to store words that satisfy the condition
List<String> resultList = new ArrayList<>();
// Iterating through each word
for (String str : words) {
// Checking if the word can be typed using one row of the keyboard
if (checkRowNumber(str)) {
// Adding the word to the result list if it satisfies the condition
resultList.add(str);
}
}
// Converting the result list to an array and returning it
return resultList.toArray(new String[0]);
}
// Method to check if a word can be typed using one row of the keyboard
public boolean checkRowNumber(String word) {
// Defining the rows of the keyboard
String row1 = "qwertyuiop", row2 = "asdfghjkl", row3 = "zxcvbnm";
// Getting the first character of the word
char firstAlphabet = word.charAt(0);
// Converting the first character to lowercase
String flag = String.valueOf(firstAlphabet).toLowerCase();
// Variable to store the row of the keyboard that the word belongs to
String keyBoardRow = "";
// Determining the row of the keyboard based on the first character
if (row1.contains(flag)) {
keyBoardRow = row1;
} else if (row2.contains(flag)) {
keyBoardRow = row2;
} else {
keyBoardRow = row3;
}
// Checking if all characters of the word belong to the same row
for (int i = 1; i < word.length(); i++) {
String flag2 = String.valueOf(word.charAt(i)).toLowerCase();
if (!keyBoardRow.contains(flag2)) {
return false;
}
}
// Returning true if all characters belong to the same row
return true;
}
}




