• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Code Chef PRGIFT Solution

August 6, 2014 by Dhaval Dave

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 T 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 ≤ a i ≤ 100
Example

Input:
4
2 1
1 2
3 2
2 6 5
3 3
2 4 5
4 2
1 2 4 5

Output:
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}.

Thanks to Dhaval for suggesting this approach and Article

Code :

#include <stdio.h>

#define gc getchar_unlocked
#define pc putchar_unlocked
inline int scan(){register int n=0,c=gc();while(c<‘0’||c>’9’)c=gc();while(c<=’9’&&c>=’0′)n=(n<<1)+(n<<3)+c-‘0’,c=gc();return n;} 

int main(void){
    int i,t,n,k,x,count=0;
t=scan();
    
while(t–){
n=scan();
k=scan();
while(n–){
x=scan();
if(x%2==0) count++;
}//while
if (count >= k) printf(“nYES“);
else printf(“nNO“);
        count=0;
}//while

 return 0;
}

//STDIN Input : 4 2 1 1 2 3 2 2 6 5 3 3 2 4 5 4 2 1 2 4 5

You can find Working code at http://ideone.com/pIhXeL

Similar Articles

Filed Under: Flipkart Interview Questions, Interview Questions, problem Tagged With: Array, codechef

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

Find position of the only set bit

Find the number ABCD such that when multipled by 4 gives DCBA.

Find shortest distances between every pair of vertices ( Dynamic Programming Floyd Warshall Algorithm)

flattens 2 D linked list to a single sorted link list

Facebook Interview Question : Interleave List

Find Pythagorean Triplets in an array in O(N)

Find the element that appears once others appears thrice

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

Number of Islands BFS/DFS

Best Java Book | Top Java Programming Book for Beginners

Introduction To Number Theory ( Part 1 )

Stickler thief

Check a String is SUBSEQUENCE of another String Find Minimum length for that ( DNA Matching )

CodeChef Code SGARDEN

Python Array String

Maximum occurred Smallest integer in n ranges

Find next greater number with same set of digits

Given a string, find the first character which is non-repetitive

Apriori algorithm C Code Data Mining

Templates in C++

Adobe Interview Questions 8 month Exp

Amazon Interview On-Campus For Internship – 1

Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

Singly linked list

Minimum insertions to form a palindrome

Wrong Directions given find minimum moves so that he can reach to the destination

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Generate largest number arranging a no. of given non negative integer numbers

N Petrol bunks or City arranged in circle. You have Fuel and distance between petrol bunks. Is it possible to find starting point so that we can travel all Petrol Bunks

Copyright © 2025 · Genesis Framework · WordPress · Log in