Skip to main content

Command Palette

Search for a command to run...

Find Consecutive Characters.

Published
1 min read
Find Consecutive Characters.
G

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.

The power of the string is the maximum length of a non-empty substring that contains only one unique character.

Given a string s, return the power of s.

LeetCode Problem: Link | Click Here

class Solution {
    public int maxPower(String s) {

        // Get the length of the input string
        int stringLength = s.length();

        // If the string has only one character, the maximum power is 1
        if (stringLength == 1) {
            return 1;
        }

        // Initialize variables to track power and consecutive characters
        int power = 1; // Keeps track of the maximum consecutive characters encountered
        int consecutiveChar = 1; // Tracks the current count of consecutive characters

        // Loop through the string to check consecutive characters
        for (int i = 0; i < stringLength - 1; i++) {
            // Check if the current character is the same as the next character
            if (s.charAt(i) == s.charAt(i + 1)) {
                consecutiveChar++; // Increment count for consecutive characters
            } else {
                consecutiveChar = 1; // Reset consecutive character count if characters are not the same
            }

            // Update the 'power' if the current consecutive count surpasses the previous recorded power
            if (consecutiveChar > power) {
                power = consecutiveChar;
            }
        }

        // Return the maximum power found in the string
        return power;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.