Sharing my Java Solution With Neat Explanation with Comments
 # Intuition  \n\n\n\n\n\n\n\n\n\n\n\n\n# Code\n\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n    // Create 
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\n\n<!-- # Complexity -->\n<!-- - Time complexity: -->\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n<!-- - Space complexity: -->\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n    // Create a HashMap to store substrings and their occurrence count\n    HashMap<String, Integer> map = new HashMap<>();\n    int maxOccurrence = 0; // Initialize the maximum occurrence count\n    \n    // Iterate through the input string \'s\' from the beginning\n    for (int i = 0; i < s.length(); i++) {\n        // Initialize a HashMap to count the occurrence of letters in the current substring\n        HashMap<Character, Integer> letterCount = new HashMap<>();\n        int distinctLetters = 0; // Initialize the count of distinct letters in the current substring\n        \n        // Nested loop to generate and process all possible substrings starting at index \'i\'\n        for (int j = i; j < s.length() && j - i + 1 <= maxSize; j++) {\n            char c = s.charAt(j); // Get the character at position \'j\' in \'s\'\n            \n            // Check if the current character \'c\' is not in the letter count map\n            if (!letterCount.containsKey(c)) {\n                distinctLetters++; // Increment the count of distinct letters\n            }\n            \n            // Update the letter count for the current character\n            letterCount.put(c, letterCount.getOrDefault(c, 0) + 1);\n            \n            // If the count of distinct letters exceeds the maximum allowed\n            // break out of the loop, as this substring won\'t satisfy the criteria\n            if (distinctLetters > maxLetters) {\n                break;\n            }\n            \n            // If the length of the current substring is at least \'minSize\'\n            if (j - i + 1 >= minSize) {\n                // Extract the current substring from \'i\' to \'j\' (inclusive)\n                String substring = s.substring(i, j + 1);\n                \n                // Update the substring count in the map\n                map.put(substring, map.getOrDefault(substring, 0) + 1);\n                \n                // Update the maximum occurrence count if needed\n                maxOccurrence = Math.max(maxOccurrence, map.get(substring));\n            }\n        }\n    }\n    \n    return maxOccurrence; // Return the maximum occurrence count of a valid substring\n}\n\n}\n```
['Java']