C++ EASY TO SOLVE || Beginner Friendly with a detailed explanation || Time-O(n) and Space-O(1)
Two Pointer Approach || Time-O(n) and Space-O(1)\n\nIntuition:\nAfter reading this question we got the gist ,that we need to find out the longest consecutive ch
# **Two Pointer Approach || Time-O(n) and Space-O(1)**\n\n**Intuition:**\nAfter reading this question we got the gist ,that we need to find out the longest consecutive character sequence of same letter\n\n*For example:*\n```\nInput: s = "abbcccddddeeeeedcba"\nOutput: 5\nExplanation: The substring "eeeee" is of length 5 with the character \'e\' only.\n```\nSo to solve this we will use two pointers approach one pointer for the starting letter and second pointer for the last letter of the sequence. Actually we can also make it a one pointer approach by adjusting the tempcount in the loop . But since both the approach will have same time complexity and space complexity we will be using two pointer approach since it\'s easy to understand.\n\n**Algorithm:**\n1. Let the two pointer\'s be `tempcount` which stores the current sequence of same characters that we are iterating and `maxcount` be the consecutive maxsequence of same characters we iterated till now\n2. We also have a base case i.e If the input string has only one letter than return 1 \n3. Now traverse the whole string and compare the consecutive letters if found same than increment the `tempcount` .\n4. After the new `tempcount` , compare it with `maxcount` & if `tempcount` is greater than `maxcount` then assign it to `maxcount` . \n5. The process 3 and 4 repeats till the end of the string\n\n**Code:-**\n```\n//Upvote and Comment\nclass Solution {\npublic:\n    int maxPower(string s) {\n        //tempcount-for currnet sequence , maxcount-for the maxsequence we iterated till now\n        int tempCount = 1,maxcount = 1,i=1;\n        //base case\n        if(s.length()==1) return 1;\n        //Loop till the end of the string\n        while(s[i]!=\'\\0\'){\n            //comparing the consecutive characters\n            if(s[i-1]==s[i]) tempCount++;\n            else tempCount = 1;\n            //if tempcount has more same charaters than maxcount, assign it to maxcount\n            if(maxcount < tempCount) maxcount = tempCount;\n            i++;\n        }\n        return maxcount;\n    }\n};\n```\n**Time Compplexity : O(n) [Takes one pass only]\nSpace Complexity : O(1)**\n
['Two Pointers', 'C', 'C++']