Company: Visa_28aug
Difficulty: medium
Count K-Identical Fruit Sections You are an inspector at a large fruit orchard. After the harvest the fruits are laid out in a row on a conveyor belt, described by an array fruits of n integers, where fruits[i] is the type of the fruit at position i . A section is a contiguous block fruits[l..r] of the belt, with 0 <= l <= r <= n - 1 . Inside a section you may form pairs : a pair is two positions of that section holding the same fruit type. The pairs must be disjoint — every position may belong to at most one pair. A section is interesting when at least k disjoint pairs can be formed inside it. Report how many sections of the belt are interesting. Input Format The first line contains two space-separated integers n and k — the number of fruits on the belt and the required number of disjoint pairs. The second line contains n space-separated integers fruits[0], fruits[1], ..., fruits[n-1] . (inferred — the source describes the problem only as a function int solution(vector<int