Company: Devrev_13nov
Difficulty: medium
Dominant Subarrays Problem Description You are given an array of N integers and a threshold K . A subarray is a contiguous stretch of the array; it cannot skip elements. A subarray is called dominant when at least one value occurs in it K times or more. Count the dominant subarrays. Function Description Complete the function dominant_subarray : int N : the number of elements. int K : the frequency a value must reach for a subarray to be dominant. int arr[N] : the array. Returns the number of dominant subarrays. The count can exceed the range of a 32-bit signed integer in general, so return a 64-bit integer. Input Format The first line contains the integer N . The second line contains the integer K . The third line contains N space-separated integers, the array elements. Output Format Print a single integer, the number of dominant subarrays. Examples Example 1 Input: 5 2 1 2 1 2 1 Output: 6 Explanation: the dominant subarrays are [1, 2, 1] starting at index 0 - the value 1 occurs twice