Company: Hitachi_13oct
Difficulty: medium
K Maxima Problem Description You are given an array A of N integers and an integer K . Count the contiguous subarrays A[l..r] whose K -th element (the element at position K of the subarray, counting from 1 at its left end, that is A[l + K - 1] ) is the maximum element of that subarray. A subarray with fewer than K elements has no K -th element, so it is never counted. The K -th element only has to be a maximum: other elements of the subarray may be equal to it, but none may be larger. (The source's own sample counts the subarray 3, 2, 3 with K = 3 , where the maximum 3 also appears first.) Two subarrays are different when their start or end positions differ, even if they hold the same values. It is guaranteed that K is not greater than N . Function Description Complete the function kMaxima in the editor with the following parameters: int N : the number of elements in the array int K : the position inside a subarray that must hold its maximum int A[N] : the array Returns: long : the num