Ab Padhai karo bina ads ke
Khareedo DN Pro and dekho sari videos bina kisi ad ki rukaavat ke!
Solution
Number of words starting with A are 4≠24
Number of words starting with I are 4!2!=12
Number of words starting with G are4!2!=12
Number of words till this=24+12+12=48,
therefore two more words are required
NAAGI and NAAIG
∴fiftieth word is NAAIG
Step by step solution by experts to help you in doubt clearance & scoring excellent marks in exams.
Open in App
Solution
- Words starting with A will have {‘A’, ‘G’, ‘I’, ‘N’} as its last four characters. So, there can be any permutation of these characters. So, no. of words starting with A = 4! = 24.
- Now, words starting with G will have {‘A’, ‘A’, ‘I’, ‘N’} as its last four characters. So, there can be any permutation of these characters. So, no. of words starting with G = 4!/2! (since ‘A’ is repeated twice) = 12.
- Similarly, words starting with I will also have 12 possible words.
- Now that count = 24+12+12 = 48>43. So, first character is ‘I’.
- Now, if second character is ‘A’, then last three characters are from {‘A’, ‘G’, ‘N’}. So, there are 3! possible words starting with ‘IA’. So, count = 24 + 12 + 6 = 42.
- Now, the next most word is the required word. So, after ‘A’, the letter ‘I’ can be followed by ‘G’. So, starting two characters are ‘IG’.
- Now, sorting the remaining characters in ascending order, we get the required word = ‘IGAAN’
53rd (explanation is given above)
In the above problem we found that starting with I is totally 48
Now starting with N is
48+12=60
We want 54th
So starting with NA
Then 3! = 6
48+6=54th
So NAIGA….
- Words starting with A will have {‘A’, ‘G’, ‘I’, ‘N’} as its last four characters. So, there can be any permutation of these characters. So, no. of words starting with A = 4! = 24.
- Now, words starting with G will have {‘A’, ‘A’, ‘I’, ‘N’} as its last four characters. So, there can be any permutation of these characters. So, no. of words starting with G = 4!/2! (since ‘A’ is repeated twice) = 12.
- Similarly, words starting with I will also have 12 possible words.
- Now that count = 24+12+12 = 48>43. So, first character is ‘I’.
- Now, if second character is ‘A’, then last three characters are from {‘A’, ‘G’, ‘N’}. So, there are 3! possible words starting with ‘IA’. So, count = 24 + 12 + 6 = 42.
- Now, the next most word is the required word. So, after ‘A’, the letter ‘I’ can be followed by ‘G’. So, starting two characters are ‘IG’.
- Now, sorting the remaining characters in ascending order, we get the required word = ‘IGAAN’
53rd (explanation is given above)
In the above problem we found that starting with I is totally 48
Now starting with N is
48+12=60
We want 54th
So starting with NA
Then 3! = 6
48+6=54th
So NAIGA….
Suggest Corrections
1
There are total 5 letters in the word AGAIN in which A appears twice.
∴ The Required number of words
To get the number of words starting with A, we fix the letter A on the extreme left position then we rearrange the remaining three letters taken all at a time.
Hence the number of words starting with A = 4! = 4 × 3 × 2 × 1
= 24
Then, starting with G, the number of words
after placing G at extreme left position, we have letters A, A, I, N.
Similarly, there are 12 words which are starting with next letter I.
Thus, so far words obtained are 24 + 12 + 12 = 48
Now the 49th word starting with N in the dictionary will be NAAGI
∴ 50th word in dictionary order = NAAIG
Last updated date: 08th Apr 2023
•
Total views: 280.5k
•
Views today: 5.53k
Answer
Verified
Hint: The words in a dictionary are arranged in alphabetical order at each stage. In this question must consider all the words in order starting with A, G, I, N. As in dictionary A will appear at first place so remaining four letters can be filled in how many ways. The number of ways of arranging the remaining 4 letters taking all at a time i.e. the number of words starts with A are $4!$. Similarly, you can find the number of words formed with other letters at first place. We have to find the word at 50th place in the dictionary according to given alphabets.
Complete step-by-step answer:
As the are placed in alphabetical order so the number of words start with letter A is given by:
[ Rightarrow ]Number of words that can be formed with A at first position $ = 4! = 24$.
Rest of the letters can be placed at first place and let us see how many words are formed from them respectively. G letter will come after A letter. So, number of words formed with first letter G is given by
[ Rightarrow ]Number of words that can be formed with G at first position $ = dfrac{{4!}}{{2!}} = dfrac{{4 times 3 times 2 times 1}}{{2 times 1}} = 12$.
Here you can see we divide $4!$ by $2!$ why? The reason behind that is that there are two A letters in the word given to us. So, to avoid repetition of words and the position of the last word appear in a dictionary whose first letter G can be given by the addition of number of words formed by A and I i.e.
$ Rightarrow $The number of words till G letter at starting = $24 + 12 = 36$.
Similarly, the number of words formed with first letter I is given by
[ Rightarrow ]Number of words that can be formed with I at first position $ = dfrac{{4!}}{{2!}} = dfrac{{4 times 3 times 2 times 1}}{{2 times 1}} = 12$.
Hence, you can find the position of last word start with letter I i.e.
$ Rightarrow $ The number of words till I letter at starting = $24 + 12 + 12 = 48$.
Now you can see the first 48 words appearing in a dictionary are from the words starting with letter A, I, G. After that the next two words i.e. word at 49th and 50th position have starting letter N.
So, look at the first two words that appear in the dictionary starting with the N alphabet are NAAGI and NAAIG in alphabetically order respectively.
Here, the word at 50th position is NAAIG.
Hence the correct option is C.
Note: The common mistake done by students in calculating the number of ways of arranging the letters is repetition when we arrange a similar alphabet the word form is the same. So, we have to divide those repeated words. If a similar alphabet repeats then the number of ways of arranging them is divided with the total ways. Here in this question, the number of letters with A is 2 so divide it by $2!$.
Permutations
Question
Moderate
Solution
Starting with the letter A and arranging the other four letters, there are 4! = 24 words. These are the first 24 words. Then, starting with G and arranging A, A, I and N in different ways, there are 4!2!1!1!=12 words, the 37th word starts with I and there are 12 words starting with I. Total goes up to 48 words.
Now, 49th word is NAAGI.
Get Instant Solutions
When in doubt download our app. Now available Google Play Store- Doubts App
Download Now
Recieve an sms with download link
OR
SCAN ME
As we learnt in
Rank of any Word —
We arrange the words according to dictionary.
Eq. for SUNIL
Rank is 95
— wherein
50th word of ‘AGAIN’
Starting with A- A-> 4!=24
Starting with G- G-> 4!/2! =12
Starting with I- A-> 4!/2! =12
Starting with N NAAGI and then NAAIG is 50th word
Option 1)
NAAGI
Incorrect
Option 2)
NAGAI
Incorrect
Option 3)
NAAIG
Correct
Option 4)
NAIAG
Incorrect
Posted by
prateek
View full answer
I want to sort out a word from main_word_list which contains all the characters from target_characters
main_word_list=['whets', 'beets', 'pelts', 'vests', 'debts', 'welts', 'seeth', 'jests', 'hefts', 'melts', 'zests', 'depth', 'pests', 'meets', 'teeth', 'lefts', 'stets', 'tests', 'wefts', 'felts', 'wests', 'bests', 'belts']
target_characters=['p', 'h', 'd', 'e']
Here only depth would be the correct answer as it was in the main_word_list as well as it has all the target_characters
lemon
12.3k5 gold badges18 silver badges35 bronze badges
asked Jun 5, 2022 at 13:56
You can do it with a list comprehension:
[w for w in main_word_list if all(c in w for c in target_characters)]
The keyword all
will check if all characters are found in the specific word.
answered Jun 5, 2022 at 14:01
lemonlemon
12.3k5 gold badges18 silver badges35 bronze badges
1
Main idea is to use python set.
- Convert yuor target characters to set.
- For each word in your list create «set represantation»
- Set comparison — trivial operation
Here code
main_word_list=[‘whets’, ‘beets’, ‘pelts’, ‘vests’, ‘debts’, ‘welts’, ‘seeth’, ‘jests’, ‘hefts’, ‘melts’, ‘zests’, ‘depth’, ‘pests’, ‘meets’, ‘teeth’, ‘lefts’, ‘stets’, ‘tests’, ‘wefts’, ‘felts’, ‘wests’, ‘bests’, ‘belts’]
target_characters=[‘p’, ‘h’, ‘d’, ‘e’]
target_characters_set=set(target_characters)
result=[]
for word in main_word_list:
word_set=set()
for char in word:
word_set.add(char)
if len(target_characters_set-word_set)==0:
result.append(word)
answered Jun 5, 2022 at 14:13
1
For a fast solution (in theory), use an array of flags initially all false, one per character in the alphabet.
Scan every word in turn and for every character, set the corresponding flag. When this is done, count the number of flags set for the target character set.
E.g. ‘whets’ -> FFFFTFFTFFFFFFFFFFTTFFTFFF giving d: F, e: T, h: T, p: F, hence two matches only.
The cost per word equals the number of letters in the word, plus the size of the target set.
Note that you need to reset the flags before processing the next word. Depending on the representation of the array of flags and the size of the alphabet, you have two options
-
clear all flags (cost proportional to the size of the alphabet),
-
scan the word again to reset the flags for all letters (cost proportional to the word length).
Pseudocode:
set= ['d'-'a', 'e'-'a', 'h'-'a', 'p'-'a'] # We work with lowercase
mask= 'FFFFFFFFFFFFFFFFFFFFFFFFFF' # Various representations are possible
# Set the flags
for letter in word:
mask[letter - 'a']= 'T'
# Count the matching flags
if Sum(mask[letter] == 'T' for letter in set) == len(set):
print(word)
# Reset the flags (alternatively, reset the whole mask)
for letter in word:
mask[letter - 'a']= 'F'
answered Jun 5, 2022 at 14:18
2
Try this:
# Check every word in main_word_list
for word in main_word_list:
# Check every character in target_characters
for char in target_characters:
# Exit the loop if the character is not in the word
if char not in word:
break
else:
# If no 'break' was encountered (i.e. all characters are in the word)
print(word) # You could also replace this with my_list.append(word)
# and define my_list before the first for loop
Alternatively with a list comprehension you can do it with all
:
my_list = [word for word in main_word_list if all(char in word for char in target_characters)]
answered Jun 5, 2022 at 14:02
The ThonnuThe Thonnu
3,5192 gold badges8 silver badges30 bronze badges
I did it this way, let me know if it’s ok
def check(word, list):
for c in list:
if c not in word:
return False
return True
final = []
for word in main_word_list:
if check(word,target_characters):
final.append(word)
print(final)
answered Jun 5, 2022 at 14:17
SnapSnap
363 bronze badges
1
This code will work:
main_word_list= ['whets', 'beets', 'pelts',
'vests', 'debts', 'welts', 'seeth', 'jests',
'hefts', 'melts', 'zests', 'depth', 'pests',
'meets', 'teeth', 'lefts', 'stets', 'tests',
'wefts', 'felts', 'wests', 'bests', 'belts']
target_characters=['p', 'h', 'd', 'e']
req_words = []
counter = 0
for word in main_word_list:
counter = 0
for char in word:
if char in target_characters:
counter+=1
if counter >= len(target_characters):
req_words.append(word)
for word in req_words:
print (word)
You will get depth
as output.
Basically what this code does is that it checks whether the number of characters in a given word is greater than or equal the length of the list target_characters
. If the length of target_characters
is greater than or equal to the number of matches found, i.e. if counter >= len(target_characters)
then that particular word is appended to another list req_words
. Value of counter
is resetted (counter=0
) after every iteration of the outermost loop, so that the next word in the main_word_list
can be checked for matches. At the end, req_words
will have all the words that have characters from target_characters
.
In case of any queries, ask me in the comments.
answered Jun 5, 2022 at 14:09
Consider using sets to evaluate whether the target character set is a subset of the each word:
>>> main_word_list=['whets', 'beets', 'pelts', 'vests', 'debts', 'welts', 'seeth', 'jests', 'hefts', 'melts', 'zests', 'depth', 'pests', 'meets', 'teeth', 'lefts', 'stets', 'tests', 'wefts', 'felts', 'wests', 'bests', 'belts']
>>> target_characters=['p', 'h', 'd', 'e']
>>> target_set = set(target_characters)
>>> [w for w in main_word_list if target_set <= set(w)] # comprehension
['depth']
>>> list(filter(target_set.issubset, main_word_list)) # functional
['depth']
answered Jun 5, 2022 at 15:23
Mechanic PigMechanic Pig
6,2773 gold badges9 silver badges29 bronze badges