The number of ways of arranging all the words of MAHESH such that all the vowels come together is

Both of your answers are incorrect.

Method 1: We arrange the consonants, then place the vowels in the spaces between and at the ends of the row.

There are $4!$ ways of arranging the four distinct consonants B, G, L, R. For each such arrangement, there are five spaces in which we could place the vowels, three between successive consonants and two at the ends of the row. To separate the vowels, we must place the three vowels in three of these five spaces. Choose two of the five spaces for the As and one of the remaining three spaces for the E. Thus, the number of admissible arrangements is $$4!\binom{5}{2}\binom{3}{1} = 720$$

Method 2: We use the Inclusion-Exclusion Principle.

There are seven letters in total, including two As, one B, one E, one G, one L, and one R. There are $\binom{7}{2}$ ways to choose two of the seven positions in the arrangement for the As. The remaining five letters can be placed in the remaining five positions in $5!$ ways. Hence, there are a total of $$\binom{7}{2}5! = \frac{7!}{2!5!} \cdot 5! = \frac{7!}{2!}$$ ways of arranging the letters of the word ALGEBRA.

From these, we must subtract those arrangements in which one or more pairs of vowels are consecutive.

A pair of vowels is consecutive: Two As are consecutive or an A and E are consecutive.

Two As are consecutive: We have six objects to arrange. They are AA, B, E, G, L, R. Since they are distinct, they can be arranged in $6!$ ways.

An A and an E are consecutive: We have six objects to arrange. They are B, E, G, L, R, and a block containing an A and an E. The six objects are distinct, so they can be arranged in $6!$ ways. The A and E can be arranged within the block in $2!$ ways. Hence, there are $6!2!$ such arrangements.

If we subtract the number of arrangements in which a pair of vowels is consecutive from the total, we will have subtracted each arrangement in which two pairs of vowels are consecutive twice, once for each way we could have designated one of those pairs as the pair of consecutive vowels. Since we only want to subtract such arrangements once, we must add them to the total.

Two pairs of consecutive vowels: Since there are only three vowels, this can only occur if the three vowels are consecutive. We have five objects to arrange, B, G, L, R, and the block of three vowels. Since the objects are distinct, they can be arranged in $5!$ ways. The three vowels can be arranged in three ways: AAE, AEA, EAA. Hence, the number of such arrangements is $5! \cdot 3$.

By the Inclusion-Exclusion Principle, the number of admissible arrangements is $$\frac{7!}{2!} - 6! - 6!2! + 5! \cdot 3 = 720$$

The number of different words that can be formed from the letters of the word INTERMEDIATE such that two vowels never come together is 151200.

Explanation:

Total number of words is INTERMEDIATE = 12

Which have 6 vowels and 6 consonants

If two vowels never come together then we can arrange as under

V C V C V C V C V C V C V

Here, vowels are IEEIAE where 2 I’s and 3 E’s are there.

∴ Number of ways of arranging vowels = `(7!)/(3!2!)` = 420.

Consonants are NTRMDT where 2T’s are there

∴ Number of ways arranging consonants = `(6!)/(2!)`

= `(6*5*4*3*2!)/(21)` = 360

So, the total number of words are = 420 × 360

= 151200

Hence, the value of the filler is 151200.

Exercise :: Permutation and Combination - General Questions

View Answer Discuss in Forum Workspace Report

View Answer Discuss in Forum Workspace Report

13. 

In how many different ways can the letters of the word 'MATHEMATICS' be arranged so that the vowels always come together?

A. 10080
B. 4989600
C. 120960
D. None of these

Answer: Option C

Explanation:

In the word 'MATHEMATICS', we treat the vowels AEAI as one letter.

Thus, we have MTHMTCS (AEAI).

Now, we have to arrange 8 letters, out of which M occurs twice, T occurs twice and the rest are different.

The number of ways of arranging all the words of MAHESH such that all the vowels come together is
Number of ways of arranging these letters =
8! = 10080.
(2!)(2!)

Now, AEAI has 4 letters in which A occurs 2 times and the rest are different.

Number of ways of arranging these letters = 4! = 12.
2!

The number of ways of arranging all the words of MAHESH such that all the vowels come together is
Required number of words = (10080 x 12) = 120960.


Page 2

Exercise :: Permutation and Combination - General Questions

View Answer Discuss in Forum Workspace Report

7. 

How many 3-digit numbers can be formed from the digits 2, 3, 5, 6, 7 and 9, which are divisible by 5 and none of the digits is repeated?

Answer: Option D

Explanation:

Since each desired number is divisible by 5, so we must have 5 at the unit place. So, there is 1 way of doing it.

The tens place can now be filled by any of the remaining 5 digits (2, 3, 6, 7, 9). So, there are 5 ways of filling the tens place.

The hundreds place can now be filled by any of the remaining 4 digits. So, there are 4 ways of filling it.

The number of ways of arranging all the words of MAHESH such that all the vowels come together is
Required number of numbers = (1 x 5 x 4) = 20.

View Answer Discuss in Forum Workspace Report

Improve Article

Save Article

Like Article

  • Read
  • Discuss
  • Improve Article

    Save Article

    Given a word containing vowels and consonants. The task is to find that in how many ways the word can be arranged so that the vowels always come together. Given that the length of the word <10.

    Examples: 

    Input: str = “geek”
    Output: 6
    Ways such that both ‘e’ comes together are 6 i.e. geek, gkee, kgee, eekg, eegk, keeg

    Input: str = “corporation”
    Output: 50400

    Approach: Since word contains vowels and consonants together. All vowels are needed to remain together then we will take all vowels as a single letter. 

    As, in the word ‘geeksforgeeks’, we can treat the vowels “eeoee” as one letter. 
    Thus, we have gksfrgks (eeoee). This has 9 (8 + 1) letters of which g, k, s each occurs 2 times and the rest are different.The number of ways arranging these letters = 9!/(2!)x(2!)x(2!) = 45360 waysNow, 5 vowels in which ‘e’ occurs 4 times and ‘o’ occurs 1 time, can be arranged in 5! /4! = 5 ways.Required number of ways = (45360 x 5) = 226800 

    Below is the implementation of the above approach: 

    #include <bits/stdc++.h>

    #define ll long long int

    using namespace std;

    ll fact(int n)

    {

        ll f = 1;

        for (int i = 2; i <= n; i++)

            f = f * i;

        return f;

    }

    ll waysOfConsonants(int size1, int freq[])

    {

        ll ans = fact(size1);

        for (int i = 0; i < 26; i++) {

            if (i == 0 || i == 4 || i == 8 || i == 14 || i == 20)

                continue;

            else

                ans = ans / fact(freq[i]);

        }

        return ans;

    }

    ll waysOfVowels(int size2, int freq[])

    {

        return fact(size2) / (fact(freq[0]) * fact(freq[4]) * fact(freq[8])

                        * fact(freq[14]) * fact(freq[20]));

    }

    ll countWays(string str)

    {

        int freq[26] = { 0 };

        for (int i = 0; i < str.length(); i++)

            freq[str[i] - 'a']++;

        int vowel = 0, consonant = 0;

        for (int i = 0; i < str.length(); i++) {

            if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i'

                && str[i] != 'o' && str[i] != 'u')

                consonant++;

            else

                vowel++;

        }

        return waysOfConsonants(consonant+1, freq) *

               waysOfVowels(vowel, freq);

    }

    int main()

    {

        string str = "geeksforgeeks";

        cout << countWays(str) << endl;

        return 0;

    }

    import java.util.*;

    class GFG{

    static int fact(int n)

    {

        int f = 1;

        for(int i = 2; i <= n; i++)

            f = f * i;

        return f;

    }

    static int waysOfConsonants(int size1,

                                int []freq)

    {

        int ans = fact(size1);

        for(int i = 0; i < 26; i++)

        {

            if (i == 0 || i == 4 || i == 8 ||

                i == 14 || i == 20)

                continue;

            else

                ans = ans / fact(freq[i]);

        }

        return ans;

    }

    static int waysOfVowels(int size2, int [] freq)

    {

        return fact(size2) / (fact(freq[0]) *

              fact(freq[4]) * fact(freq[8]) *

             fact(freq[14]) * fact(freq[20]));

    }

    static int countWays(String str)

    {

        int []freq = new int [200];

        for(int i = 0; i < 200; i++)

            freq[i] = 0;

        for(int i = 0; i < str.length(); i++)

            freq[str.charAt(i) - 'a']++;

        int vowel = 0, consonant = 0;

        for(int i = 0; i < str.length(); i++)

        {

            if (str.charAt(i) != 'a' && str.charAt(i) != 'e' &&

                str.charAt(i) != 'i' && str.charAt(i) != 'o' &&

                str.charAt(i) != 'u')

                consonant++;

            else

                vowel++;

        }

        return waysOfConsonants(consonant + 1, freq) *

               waysOfVowels(vowel, freq);

    }

    public static void main(String []args)

    {

        String str = "geeksforgeeks";

        System.out.println(countWays(str));

    }

    }

    def fact(n):

        f = 1

        for i in range(2, n + 1):

            f = f * i

        return f

    def waysOfConsonants(size1, freq):

        ans = fact(size1)

        for i in range(26):

            if (i == 0 or i == 4 or

                i == 8 or i == 14 or

                i == 20):

                continue

            else:

                ans = ans // fact(freq[i])

        return ans

    def waysOfVowels(size2, freq):

        return (fact(size2) // (fact(freq[0]) *

                fact(freq[4]) * fact(freq[8]) *

                fact(freq[14]) * fact(freq[20])))

    def countWays(str1):

        freq = [0] * 26

        for i in range(len(str1)):

            freq[ord(str1[i]) -

                 ord('a')] += 1

        vowel = 0

        consonant = 0

        for i in range(len(str1)):

            if (str1[i] != 'a' and str1[i] != 'e' and

                str1[i] != 'i' and str1[i] != 'o' and

                str1[i] != 'u'):

                consonant += 1

            else:

                vowel += 1

        return (waysOfConsonants(consonant + 1, freq) *

                waysOfVowels(vowel, freq))

    if __name__ == "__main__":

        str1 = "geeksforgeeks"

        print(countWays(str1))

    using System.Collections.Generic;

    using System;

    class GFG{

    static int fact(int n)

    {

        int f = 1;

        for(int i = 2; i <= n; i++)

            f = f * i;

        return f;

    }

    static int waysOfConsonants(int size1,

                                int []freq)

    {

        int ans = fact(size1);

        for(int i = 0; i < 26; i++)

        {

            if (i == 0 || i == 4 || i == 8 ||

                i == 14 || i == 20)

                continue;

            else

                ans = ans / fact(freq[i]);

        }

        return ans;

    }

    static int waysOfVowels(int size2, int [] freq)

    {

        return fact(size2) / (fact(freq[0]) *

              fact(freq[4]) * fact(freq[8]) *

             fact(freq[14]) * fact(freq[20]));

    }

    static int countWays(string str)

    {

        int []freq = new int [200];

        for(int i = 0; i < 200; i++)

            freq[i] = 0;

        for(int i = 0; i < str.Length; i++)

            freq[str[i] - 'a']++;

        int vowel = 0, consonant = 0;

        for(int i = 0; i < str.Length; i++)

        {

            if (str[i] != 'a' && str[i] != 'e' &&

                str[i] != 'i' && str[i] != 'o' &&

                str[i] != 'u')

                consonant++;

            else

                vowel++;

        }

        return waysOfConsonants(consonant + 1, freq) *

               waysOfVowels(vowel, freq);

    }

    public static void Main()

    {

        string str = "geeksforgeeks";

        Console.WriteLine(countWays(str));

    }

    }

    <script>

    function fact(n)

    {

           let f = 1;

        for(let i = 2; i <= n; i++)

            f = f * i;

        return f;

    }

    function waysOfConsonants(size1,freq)

    {

        let ans = fact(size1);

        for(let i = 0; i < 26; i++)

        {

            if (i == 0 || i == 4 || i == 8 ||

                i == 14 || i == 20)

                continue;

            else

                ans = Math.floor(ans / fact(freq[i]));

        }

        return ans;

    }

    function waysOfVowels(size2,freq)

    {

        return Math.floor(fact(size2) / (fact(freq[0]) *

              fact(freq[4]) * fact(freq[8]) *

             fact(freq[14]) * fact(freq[20])));

    }

    function countWays(str)

    {

        let freq = new Array(200);

        for(let i = 0; i < 200; i++)

            freq[i] = 0;

        for(let i = 0; i < str.length; i++)

            freq[str[i].charCodeAt(0) - 'a'.charCodeAt(0)]++;

        let vowel = 0, consonant = 0;

        for(let i = 0; i < str.length; i++)

        {

            if (str[i] != 'a' && str[i] != 'e' &&

                str[i] != 'i' && str[i] != 'o' &&

                str[i] != 'u')

                consonant++;

            else

                vowel++;

        }

        return waysOfConsonants(consonant + 1, freq) *

               waysOfVowels(vowel, freq);

    }

    let str = "geeksforgeeks";

    document.write(countWays(str));

    </script>

    Time complexity: O(n) where n is the length of the string
    Auxiliary space: O(1) 

    Further Optimizations: We can pre-compute required factorial values to avoid re-computations.