Company: Texas

Difficulty: medium

Problem Statement

Sum of Endpoint Frequency Differences in Subarrays Given an integer array `A` of length `N` and an integer `K`, consider every contiguous subarray of length `K`. For each such subarray, count how many times its first value occurs in that subarray and how many times its last value occurs. Add the absolute difference of these two counts over all subarrays. Input Format The first line contains `N` and `K`. The second line contains `N` integers of `A`. Output Format Print the required sum. Notes `1 <= K <= N`. If the first and last values are equal, their frequencies are equal and that subarray contributes zero. Example Input: `6 3` followed by `5 5 4 4 4 4`. Output: `2`. The four windows contribute `1, 1, 0, 0`.

More Texas OA questionsInterview experiences