Happy Neighbourhood
In a neighbourhood, there are N empty houses numbered from 1 to N arranged in a line. Each day, starting from day 1, one house will be occupied by residents. The sequence of occupied houses is given as a permutation of length N. On the ith day, the house with the number given by the ith element of the permutation will be occupied.
The neighbourhood will be considered happy if there is at least one set of consecutive occupied houses. On which day will the neighbourhood become happy?
Note: A permutation of length N is an array of N integers where each element is between 1 and N, with no repetitions.
Complete the function solve. This function takes the following 3 parameters and returns the required answer.
N: Represents the number of housesM: Represents the number of consecutive houses neededhouse: Represents an array indicating the house that will be filled on each dayInput format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code.
N denoting the number of houses.M denoting the number of consecutive houses needed.house denoting the house that will be filled on each day.Output format
Print a single integer representing the first day on which the neighbourhood becomes happy.
Note:
Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.
Limits
- Time Limit:
1.0 sec(s)for each input file - Memory Limit:
256 MB - Source Limit:
1024 KB
Scoring
Score is assigned if any testcase passes
1Example 1
2Example 2
3Example 3
4Example 4
Constraints
Limits and guarantees your solution can rely on.
1 ≤ N ≤ 10^51 ≤ M ≤ N1 ≤ house[i] ≤ N