Given a string containing lower and uppercase alphabets, the task is to find the maximum number of characters between any two same character in the string.
Input: S = "socks" Output: 3 Explanation: There are 3 characters between the two occurrences of 's'.
Input: S = "FoR" Output: -1 Explanation: No repeating character present.
You don't need to read input or print anything. Your task is to complete the function maxChars() which takes the string S as input and returns the maximum number of characters between any two same characters in the string.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes