If we want to find out the number of ways NOT to do something, we could break it down into the subcases that are allowed and then combine those. Sometimes this may be inefficient as there might be many more subcases that are allowed than there are ones that are not. We note that a subcase may either be allowed or not allowed leading to the following equation:

total number of ways=subcases allowed+subcases not allowedtotal \ number \ of \ ways = \sum{subcases \ allowed} + \sum{subcases \ not \ allowed}

From this equation, we can see that if the number of cases not allowed is smaller than the number of cases allowed, we can calculate the number of cases allowed by rearranging the formula to get

subcases allowed=total number of wayssubcases not allowed \sum{subcases \ allowed} = total \ number \ of \ ways - \sum{subcases \ not \ allowed}

Let’s see how this works. How many ways can we rearrange the letters in the word YAHOO such that the two O’s are not together? We could consider every possible case in which the two letters are not together (YAOHO + OYAHO + etc…) which requires much more work than simply counting the number of ways the two letters are together and the total number of ways we can rearrange the word. The total number of permutations of the word YAHOO is:


Remember, we divide by 2! because there are two O’s.

The number of ways we can rearrange the word with the two O’s next to either is done by combining the two O’s into one super letter and then computing the number of arrangements we can have of the letters Y, A, H, and OO so 4!. So the total number of ways NOT allowing the two O’s together is

5!2!4!=36 \frac{5!}{2!} - 4! = 36

36 ways of rearranging the word YAHOO without the two O’s being together.



Recall that a New York state license plate is composed of three letters and a four-digit number. How many license plate numbers are possible? As a refresher, calculate this number. Store your answer in the license_plates variable.


Let’s say that no letter is allowed to appear more than twice. How many cases are NOT allowed? Store your answer in the plates_not_allowed variable.


How many valid license plates are there if no letter is allowed to appear more than twice? Store your answer in the valid_plates variable.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?