Number of Changing Keys

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.
You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any.
Return the number of times the user had to change the key.
Note: Modifiers like shift or caps lock won't be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.
LeetCode Problem - 3019: Link | Click Here
class Solution {
// Method to count the number of key changes in a given string
public int countKeyChanges(String s) {
// Initialize a variable to keep track of the count of changing keys
int countChangingKey = 0;
// Get the lowercase of the first character to compare with subsequent characters
char compare = Character.toLowerCase(s.charAt(0));
// Iterate through the string starting from the second character
for (int i = 1; i < s.length(); i++) {
// Get the lowercase of the current character
char currentChar = Character.toLowerCase(s.charAt(i));
// Compare the current character with the previous one
if (compare != currentChar) {
// If different, update the compare variable and increment the count of changing keys
compare = currentChar;
countChangingKey++;
}
}
// Return the count of changing keys
return countChangingKey;
}
}




