Skip to content

Deepam-Aggarwal/interviewquestions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Interview questions

NOTE:If you having any difficulty in solving then you can message me for solution

Question 1

Rahman has N coins; let's denote the value of coin i by vi. Since today is Eid, Rahman is going to give one coin to each of his two children. He wants the absolute value of the difference between the values of coins given to the two children to be as small as possible, so that he would be as fair as possible. Help Rahman by telling him the minimum possible difference between the values of the coins given to the two children. Of course, Rahman cannot give the same coin to both children.

Input
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains a single integer N.
• The second line contains N space-separated integers v1,v2,…,vN.

Output
For each test case, print a single line containing one integer — the minimum possible difference.
Constraints
• 1≤T≤100
• 2≤N≤105

Example Input
2
3
1 4 2
3
1 3 3

Example Output
1
0

Explanation
Example case 1: Chef gives the coin with value 1 to his first child and the coin with value 2 to the second child, so the answer is 2−1=1.
Example case 2: Chef gives each of his children a coin with value 3, so the difference is 0

Question 2

Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters.

You just received a message given by a string s. You don't know whether this message is sent by Chef or his brother. Also, the communication channel through which you received the message is erroneous and hence can flip a letter from uppercase to lowercase or vice versa. However, you know that this channel can make at most K such flips.

Determine whether the message could have been sent only by Chef, only by the little brother, by both or by none.

Input
• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains two space-separated integers N and K denoting the length of the string s and the maximum number of flips that the erroneous channel can make.
• The second line contains a single string s denoting the message you received.

Output
For each test case, output a single line containing one string — "chef", "brother", "both" or "none".

Constraints
• 1 ≤ T ≤ 1000
• 1 ≤ N ≤ 100
• 0 ≤ K ≤ N
• s consists only of (lowercase and uppercase) English letters

Example Input
4
5 1
frauD
5 1
FRAUD
4 4
Life
10 4
sTRAWBerry

Output
chef
brother
both
none

Answer is here

Question 3

Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.

He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.

Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j
Input:
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output:
n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not

Example

Author

Readme Card Readme Card Readme Card Readme Card Deepam's GitHub stats Top Langs