Largest 3-Same-Digit Number in String

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 string num representing a large integer. An integer is good if it meets the following conditions:
It is a substring of
numwith length3.It consists of only one unique digit.
Return the maximum good integer as a string or an empty string "" if no such integer exists.
Note:
A substring is a contiguous sequence of characters within a string.
There may be leading zeroes in
numor a good integer.
LeetCode Problem - 2264
class Solution {
// Method to find the largest good integer substring in a given string
public String largestGoodInteger(String num) {
// Initialize a flag to keep track of the largest good integer found
int flag = Integer.MIN_VALUE;
// Iterate through the string, considering each possible substring of length 3
for(int i = 0; i < num.length() - 2; i++) {
// Extract the three digits of the current substring
int check = num.charAt(i) - '0', a = num.charAt(i + 1) - '0', b = num.charAt(i + 2) - '0';
// Calculate the integer value of the current substring
int substring = (check * 100) + (a * 10) + b;
// Check if all three digits are equal
if(check == a && check == b) {
// If the current substring is greater than the current flag, update the flag
if(substring > flag) {
flag = substring;
}
}
}
// If no good integer is found, return "000"
if(flag == 0) {
return "000";
}
// If the flag remains negative, return an empty string; otherwise, return the flag as a string
return flag < 0 ? "" : String.valueOf(flag);
}
}




