chef and gift

This problem was of those cases that I like the most, it was based on finding the vulnerabilities in the possibilities. Try to think of the solution but with that also try to find some flaws in the solution that you have thought of, bcz this helps in building that habit of thinking and finding the most optimal and logical approach and idea, bcz if we just try to submit the code and hope that it would pass then even if it did then also it would be of no use at all. So, we should always try to make an image of the problem clearly in our mind and then try to think of the solution bcz in this way we are not just solving the problem but we are making and training our mind to think in the context of the current problem when we see another problem like the current one afterwards. 


                                                  If you didn't get this... then, "pip uninstall yourself" 


This is the most important part that we often ignore, the same applies to Chess too, we may win a game or lose other but were we calculating every possibility in both of those games? This is the main question we should be worrying about. We may win 5 games in a row but if we ignored a single possibility then we should consider it as something that can be the main reason for our next loss.

Problem Statement:-

Today is chef's friend's birthday. He wants to give a gift to his friend. So he was desperately searching for some gift here and there.

Fortunately, he found an array a of size n lying around. The array contains positive integers. Chef's friend likes even numbers very much. So for the gift, chef will choose a consecutive non-empty segment of the array. The segment should contain exactly k even integers. Though it can have any number of odd integers. He will then pick that segment and gift it to his friend.

But there is a problem. It might not be always possible for the chef to choose such a segment. Please tell whether it is possible for chef to select some gift or not?

Input

First line of the input contains a single integer denoting number of test cases. For each test case, first line contains two space separated integers n, k. Next line contains n space separated integers denoting content of array a. It is also guaranteed that all the numbers in the array a are distinct.

Output

For each test case, print a single line containing "YES" or "NO" (without quotes) corresponding to the situation.

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ n ≤ 50
  • 0 ≤ k ≤ n
  • 1 ≤ ≤ 100

Note

A consecutive non empty segment of array a is a segment a[l], a[l + 1] , , a[r] such that 1 ≤ l ≤ r ≤ n.

Sample 1:

Input
Output
4
2 1
1 2
3 2
2 6 5
3 3
2 4 5
4 2
1 2 4 5
YES
YES
NO
YES

Explanation:

For first test case, we can select a[2, 2] = {2}. For second test case, we can select a[1, 2] = {2, 6}. For third test case, we can not select any consecutive segment having exactly 3 even numbers. For fourth test case, we can select a[2, 3] = {2, 4}.

Code Implementation:-

for _ in range(int(input())):
    n,k=map(int,input().split())
    count,nums=0,list(map(int,input().split()))
    for num in nums:
        if(num%2==0):
            count+=1
    if(k==0 and count==len(nums)):
        print("NO")
        continue
    if(count>=k):
        print("YES")
    else:
        print("NO")

Explanation:-

This was one of the best problems on finding the hidden corner case, and this took me somewhat 20 mins, and out of this time, about 14 mins were just because of that corner case only. The problem just asks you to tell if it is possible to have a "Non-Empty" consecutive segment out of the array given, provided this segment can have any number of odd nos. and it should have "exactly" k number of even numbers. These two marked words are the main things to consider in this problem statement. Now, when we consider in general then we just think that we need to have k number of even nums at minimum so, it's very straightforward that if we have k or more even nums then it is possible to get the segment required else not. This was the first idea that I had thought of. But let's take the corner case of k=0, now if we think that ok, we need 0 evens so obviously we are satisfying the condition right? But there is a big no here. When we consider k=0, then suppose all the nums in the array are odd, now you need 0 evens in the segment, so how are you gonna do that? This was the corner case they wanted us to think about, we cannot come up with a segment because we have all even numbers and we don't want any even in the segment so the segment will be necessarily empty and this negates the condition for the segment thus it is not possible in this case to generate a segment. The very first "if" condition after the loop is taking care of this case. And for all k values greater than 0, we just go with the normal idea. Although this problem would have been interesting in one more context, if we had to find if there are k even nums in contiguous manner in the array and no odd number should be in between them.


Comments

Popular Posts