Rings and Rods

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.
There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.
You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where:
The first character of the
i<sup>th</sup>pair denotes thei<sup>th</sup>ring's color ('R','G','B').The second character of the
i<sup>th</sup>pair denotes the rod that thei<sup>th</sup>ring is placed on ('0'to'9').
For example, "R3G2B1" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.
Return the number of rods that have all three colors of rings on them.
LeetCode Problem - 2103
class Solution {
public int countPoints(String rings) {
int answer = 0; // Initialize the answer counter
// Iterate over numbers 0-9 (as characters)
for(int i=0; i<10; i++){
boolean red = false;
boolean green = false;
boolean blue = false;
char flag = (char) (i + '0'); // Convert integer to character ('0'-'9')
// Iterate through the rings string
for(int j=0; j<rings.length(); j++){
char c = rings.charAt(j); // Get the current character in the rings string
if(flag == c){ // Check if the current character matches the current number (0-9)
char color = rings.charAt(j-1); // Get the color before the current character
// Set corresponding color flag to true based on the color before the number
if(color == 'R'){
red = true;
} else if(color == 'B'){
blue = true;
} else if (color == 'G'){
green = true;
}
}
// If all three colors are found (red, green, blue), increment answer and break the loop
if(red && blue && green){
answer++;
break;
}
}
}
return answer; // Return the total number of points counted
}
}




