Untitled

 avatar
unknown
plain_text
a month ago
487 B
0
Indexable
public int numSubarrayBoundedMax(int[] arr, int left, int right) {
    int i = 0;
    int j = 0;
    int cnt = 0;
    int n = arr.length;

    while (j < n) {
        if (arr[j] < left) {
            j++;
            continue;
        } else if (arr[j] > right) {
            i = j + 1;
            j++;
            continue;
        }

        // Calculate the number of valid subarrays ending at j
        cnt += j - i + 1;
        j++;
    }

    return cnt;
}
Leave a Comment