Codey and Recipes
https://www.hackerrank.com/contests/codenection-2024-preliminary-round-open-category/challenges/cn24-8
Question
Codey wants to impress Zoey by recreating some of Zoey's secret recipes using the ingredients in his kitchen.
Codey lined up all its n ingredients from left to right in its kitchen. The kitchen can be represented as an array a of length n, where represents the type of ingredient at i-th position. Zoey's secret recipe is array t of length m, where represent the type of ingredient needed for its special dish.
As a beginner cook, Codey struggles to recognize the different ingredients. It decides to select a subarray of m consecutive ingredients from its kitchen (from array a). To replicate the flavor of Zoey's dish, Codey must ensure that at least p ingredients from this selected subarray is contained in t.
For example, if the target recipe and , then:
the subarray will impress Zoey because it contains at least 2 ingredients from
t.the subarray will not impress Zoey.
Help Codey count how many subarrays of m ingredients it can find in its kitchen that meet Zoey's criteria.
Input Format
The first line contains three integers n, m, and p, where n represents the number of ingredients in Codey’s kitchen, m represents the number of ingredients in Zoey's recipe, and p represents the minimum number of ingredients in the selected subarray that must also appear in Zoey's recipe.
The second line contains n integers , each representing the type of ingredients in Codey's kitchen.
The third line contains m integers , each representing the type of ingredients needed for the recipe.
Constraints
Elements of the array a and t are not necessarily unique.
Output Format
Output the number of subarrays of m ingredients Codey can find in its kitchen that meet Zoey's criteria.
Sample Inputs:
Last updated