Java sliding window generic template solution
IntuitionUsually question would ask smallest substring - but we are asked the count here. Whatever the substrings having length > substring that obey the condit
# Intuition
Usually question would ask smallest substring - but we are asked the count here. Whatever the substrings having length > substring that obey the condition should be automatically be counted.

# Approach
1. Find the smallest string string obeying the condition
2. for this solution, Add the word1.length() - endIndex will take care of string of sizes more than that.

Algo - 
1. For each end index - consider the end index to update current frequency array.
2. while our substring follows the given condition - keep on reducing the start index untill it does not follow.
3. in the main while loop keep on adding end.


# Complexity
- Time complexity:
$$O(n)$$

- Space complexity:
$$O(1)$$ - 26 fix size.

# Code
```java []
class Solution {
    public long validSubstringCount(String word1, String word2) {
        // count the substrings with  >= frequ count as word2
        int[] prefix = new int[26];
        Arrays.fill(prefix, 0);
        for(char c: word2.toCharArray()) {
            prefix[c - 'a']++;
        }

        int start = 0, end = 0;
        long count = 0;
        int[] current = new int[26];
        while(end < word1.length()) {
            current[word1.charAt(end) - 'a']++;

            while(isValid(current, prefix)) {
                count+= (long) (word1.length() - end);

                current[word1.charAt(start) - 'a']--;
                start++;
            }
            end++;
        }

        return count;
    }

    private boolean isValid(int[] current, int[] prefix) {
        for(int i=0; i< 26; i++) {
            if(current[i] < prefix[i]) {
                return false;
            }
        }
        return true;
    }
}
```
['Java']