Problem Statement:
John is a 5-year-old kid who is eager to learn English words. Recently he has learnt all the
alphabets and now he wants to learn English words. Anne, John's mother has a bucket of
alphabets and she decided to teach her child English words using a new method. Anne’s plan is
to use the bucket of alphabets to make him learn English words, she will tell the word to John
and he has to pick the alphabets from the bucket to make that word.
Now you are going to help John find out if he can form the given word with the bucket of
alphabets that Anne has given to John.
Your program should print "YES" if John can form the given word with the given bucket of
alphabets and "NO" if John cannot form the given word with the given bucket of alphabets.
Note:
All alphabets and words are in upper case.
Alphabets in the bucket can be duplicates.
If a word has duplicate letters, for example "PARROT". Then the bucket of alphabets should
have 2 'R' to decide this word to be "YES" in the output.Alphabets are taken out of the bucket as the words are formed. (Alphabets used in the 1 st word
are taken out of the bucket after it is formed. Next word is formed based on the only remaining
alphabets in the bucket and so on.)
Input:
Line 1 - English alphabets in bucket with comma separated
Line 2 - No of words(n) that Anne going to give to John
next n lines - words that Anne gave to John
Output:
n lines of "YES" or "NO"
Example 1:
Input:
H, F, B, A, C, L, K, G, V, C, B, I, U, K, F
1
BLACKBUCK
Output:
YES
Explanation:
The bucket of alphabets has all the letters in the given word "BLACKBUCK" so the output
is "YES"
Example 2:
Input:
Q, W, E, R, T, Y, U, I, O, P, A, S, D, F, G, H, B, N, L, U, Y, T, U, E, W, M
2
AWESOME
INSIGHT
Output:
YES
NO
Explanation:The bucket of alphabets has all the letters in the first given word "AWESOME" but few
alphabets from the given word "INSIGHT" is missing in the output. Therefore, the output
is "YES" and "NO".
Answers
Answered by
6
Answer:
yes and no also
Answered by
0
Answer: Copy and Paste the below Python code
bucket = list(map(str,input().split(",")))
word = input()
y=n=0
for i in word:
if i in bucket:
y+=1
else:
n+=1
if(y>n):
print("YES")
else:
print("NO")
#SPJ3
Similar questions