Placement Aptitude (Quant, Logical, Verbal) Module 9 – Counting, probability and statistics
Permutations and arrangements
Count arrangements with the multiplication principle and nPr: repeated digits, identical letters, together or apart, round tables and the rank of a word.
What you will learn
- Apply the multiplication and addition principles of counting
- Count arrangements with repetition, identical items and restrictions
- Count circular arrangements and find the rank of a word
What you’ll learn
What you will learn
- Apply the multiplication and addition principles of counting
- Count arrangements with repetition, identical items and restrictions
- Count circular arrangements and find the rank of a word
On this page
Permutations are arrangements of objects in a definite order, and two rules count them. The multiplication principle says that when one choice follows another, the numbers of ways multiply; the addition principle says that when a task can be done in one of several separate ways, the numbers add. Filling first, second and third place from 5 runners gives 5 × 4 × 3 = 60 arrangements, written 5P3. Aptitude items then change one condition: digits that may repeat, letters that are identical, people who sit together or apart, a round table instead of a row, or a word’s position in dictionary order. Each condition has a short method, set out below with five solved examples, an exercise and ten untimed questions.
The two principles and nPr
NCERT’s Class 11 textbook calls the multiplication rule the fundamental principle of counting. A thali with one of 4 curries and one of 3 breads can be served in 4 × 3 = 12 ways; an order of either one of 4 curries or one of 3 desserts can be placed in 4 + 3 = 7 ways. Permutations of r objects taken from n different objects number nPr = n!/(n − r)!, where n! = n × (n − 1) × … × 1 and 0! = 1. When an object may be used again, every place has all n choices, so there are nʳ arrangements: a 4-digit PIN has 10⁴ = 10,000.
Places in order, a glued block for "together" and gaps for "apart"
Text description of the diagram
The figure has three rows.
The first row counts the ways to fill 1st, 2nd and 3rd place from 5 runners. Three boxes hold the choices left for each place, 5, 4 and 3, joined by multiplication signs: 5 × 4 × 3 = 60, which is 5P3.
The second row counts seatings of five friends in a row when Asha and Bala sit together. A and B are glued into one wide box, followed by single boxes C, D and E: four units arranged in 4! = 24 orders, times 2! = 2 orders of A and B inside the block, gives 48.
The third row counts the seatings with Asha and Bala apart. C, D and E sit first, with a dashed gap before, between and after them: four gaps. C, D and E have 3! = 6 orders, and A and B take two different gaps in order, 4P2 = 12 ways, so 6 × 12 = 72. This agrees with 5! − 48 = 120 − 48 = 72.
Conditions and their methods
| Condition | Method | Example |
|---|---|---|
| Identical items | Divide by the orders of each repeated item: n!/(p! q! …) | MISSISSIPPI: 11!/(4! × 4! × 2!) = 34,650 |
| Some must be together | Glue them into one unit, then multiply by their own orders | Row 2 of the figure |
| Some must be apart | All arrangements minus “together”, or seat the others and use the gaps | Row 3 of the figure |
| A round table | (n − 1)!, because turning the table changes no one’s neighbours | 6 people: 5! = 120 |
| A necklace | (n − 1)!/2 for 3 or more beads, because turning it over changes nothing either | 5 beads: 4!/2 = 12 |
| A word’s rank | Count the words that start with smaller letters, one position at a time | PUNE is 18th |
For PUNE, put the letters in order: E, N, P, U. Words that begin with E or N come first, 2 × 3! = 12 of them. After P, the letters left that come before U are E and N, which start 2 × 2! = 4 more words, and after PU, E comes before N, which adds 1. That is 17 words before PUNE, so its rank is 18.
Five solved examples
- Three posts. A class of 8 elects a president, a secretary and a treasurer, and nobody holds two posts. The posts differ, so order matters: 8P3 = 8 × 7 × 6 = 336.
- Even numbers. Four-digit even numbers made from the digits 1 to 6: if digits may repeat, the last place has 3 choices and the others 6 each, so 6 × 6 × 6 × 3 = 648. If no digit repeats, fill the last place first: 3 × 5P3 = 180. Starting with the restricted place is the habit that prevents most errors.
- Identical letters. ALLAHABAD has nine letters, with four A’s and two L’s, so it has 9!/(4! × 2!) = 3,62,880 ÷ 48 = 7,560 arrangements.
- Never together. Five friends sit in a row, and Asha and Bala will not sit side by side. All seatings: 5! = 120. Together, glued into one unit: 4! × 2! = 48. Apart: 120 − 48 = 72. The gaps agree: seat the other three in 3! ways, then give Asha and Bala 2 of the 4 gaps in order, 4P2 = 12 ways, and 6 × 12 = 72.
- A round table. Seven people sit at a round table, and Bala and Chitra must sit next to each other. Glued together they make 6 units, which go round the table in 5! = 120 ways, and the pair has 2 orders: 240.
# The five solved examples of the lesson and the rank of PUNE, each counted twice: once with the formula and once
# by listing every arrangement with itertools. Then nPr is checked against a full listing for every n up to 8.
from itertools import permutations, product
from math import factorial, perm
def grouped(n):
"""Digits grouped the Indian way: 7,560 and 3,62,880."""
s = str(n)
if len(s) <= 3:
return s
head, tail = s[:-3], s[-3:]
pairs = []
while len(head) > 2:
pairs.insert(0, head[-2:])
head = head[:-2]
return ','.join([head, *pairs, tail])
def listed(items, keep=lambda arrangement: True, length=None):
"""How many different arrangements of the items pass the test (identical letters give one arrangement)."""
return len({a for a in permutations(items, length) if keep(a)})
# 1. President, secretary and treasurer from 8 students: 8P3.
print(f"1. Three posts from 8 students: 8P3 = {perm(8, 3)}, listed {listed(range(8), length=3)}")
# 2. Four-digit even numbers from the digits 1 to 6, with and without repeating a digit.
digits = range(1, 7)
with_repeats = sum(1 for d in product(digits, repeat=4) if d[-1] % 2 == 0)
without = listed(digits, keep=lambda d: d[-1] % 2 == 0, length=4)
print(f"2. Even, digits may repeat: 6 × 6 × 6 × 3 = {6 * 6 * 6 * 3}, listed {with_repeats}; "
f"no repeats: 3 × 5P3 = {3 * perm(5, 3)}, listed {without}")
# 3. The letters of ALLAHABAD: four A's and two L's.
formula = factorial(9) // (factorial(4) * factorial(2))
print(f"3. ALLAHABAD: 9!/(4! × 2!) = {grouped(formula)}, listed {grouped(listed('ALLAHABAD'))} "
f"among {grouped(factorial(9))} orders of the nine letters")
# 4. Five friends in a row; Asha and Bala never sit side by side.
apart = lambda row: abs(row.index('A') - row.index('B')) != 1
print(f"4. Never together: 5! − 4! × 2! = {factorial(5) - factorial(4) * 2}, "
f"gaps 3! × 4P2 = {factorial(3) * perm(4, 2)}, listed {listed('ABCDE', keep=apart)}")
# 5. Seven people at a round table; Bala and Chitra sit side by side. Seatings that differ only by a rotation are
# the same, so Asha is fixed in seat 0 and the other six fill seats 1 to 6.
def side_by_side(rest):
table = ('A',) + rest
gap = (table.index('B') - table.index('C')) % 7
return gap in (1, 6)
print(f"5. Round table, pair together: 2 × 5! = {2 * factorial(5)}, "
f"listed {listed('BCDEFG', keep=side_by_side)} of the {factorial(6)} seatings")
# The rank of PUNE among its arrangements in dictionary order.
orders = sorted(''.join(a) for a in permutations('PUNE'))
print(f"Rank of PUNE: 2 × 3! + 2 × 2! + 1 × 1! + 1 = {2 * 6 + 2 * 2 + 1 + 1}, listed {orders.index('PUNE') + 1}")
# nPr = n!/(n − r)! against a full listing for every 1 <= r <= n <= 8.
pairs = [(n, r) for n in range(1, 9) for r in range(1, n + 1)]
agree = sum(1 for n, r in pairs if factorial(n) // factorial(n - r) == listed(range(n), length=r))
print(f"nPr matched the listing for {agree} of {len(pairs)} pairs (n, r) with n up to 8") Output
1. Three posts from 8 students: 8P3 = 336, listed 336 2. Even, digits may repeat: 6 × 6 × 6 × 3 = 648, listed 648; no repeats: 3 × 5P3 = 180, listed 180 3. ALLAHABAD: 9!/(4! × 2!) = 7,560, listed 7,560 among 3,62,880 orders of the nine letters 4. Never together: 5! − 4! × 2! = 72, gaps 3! × 4P2 = 72, listed 72 5. Round table, pair together: 2 × 5! = 240, listed 240 of the 720 seatings Rank of PUNE: 2 × 3! + 2 × 2! + 1 × 1! + 1 = 18, listed 18 nPr matched the listing for 36 of 36 pairs (n, r) with n up to 8
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 check_five.py
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
The program lists every arrangement with Python’s itertools.permutations and keeps the ones that fit, so no formula is
involved in its counts. It also compared nPr with a full listing for all 36 pairs of n and r with n up to 8, and every
pair agreed.
Exercise: arrangements and the rank of a word
The exercise turns the rank method into a short program that also handles repeated letters, and the ten questions after it are untimed.
Exercise · Medium · Python
Count the arrangements of a word and find its rank
Write two functions in ranks.py, the file the tests import. A word is a string of capital letters, and a letter may appear more than once.
arrangements(word)returns how many different arrangements its letters have:arrangements("PUNE")is 24 andarrangements("ALLAHABAD")is 7,560, because swapping two identical letters gives the same word.rank(word)returns the word's position when all its different arrangements are listed in dictionary order, counting from 1:rank("PUNE")is 18, as in the lesson.
Work the counts out with factorials instead of listing the arrangements: the tests include VISAKHAPATNAM, whose 13 letters can be put in order in more than 622 crore ways, so a listing would not finish in time.
Starter code · ranks.py
from collections import Counter
from math import factorial
def arrangements(word):
"""How many different arrangements the letters of the word have."""
# Replace this line with your code.
return 0
def rank(word):
"""The word's position, from 1, among its different arrangements in dictionary order."""
# Replace this line with your code.
return 0 The sample tests · test_ranks.py
from ranks import arrangements, rank
def test_counts_with_and_without_repeats():
"""Four different letters, then ALLAHABAD's four A's and two L's"""
assert arrangements("PUNE") == 24
assert arrangements("ALLAHABAD") == 7560
def test_the_lesson_word():
"""PUNE: 12 + 4 + 1 words come before it"""
assert rank("PUNE") == 18
def test_first_and_last_words():
"""Letters in order give the first word, letters in reverse order the last"""
assert rank("ADGNOS") == 1
assert rank("SONGDA") == arrangements("SONGDA")
def test_repeated_letters():
"""ASSAM has 30 different arrangements"""
assert arrangements("ASSAM") == 30
assert rank("ASSAM") == 11
def test_one_letter_and_all_alike():
"""A single letter, and a word whose letters are all the same"""
assert arrangements("Q") == 1 and rank("Q") == 1
assert arrangements("AAAA") == 1 and rank("AAAA") == 1
def test_a_long_word_without_listing():
"""Thirteen letters, four of them A: worked out, never listed"""
assert arrangements("VISAKHAPATNAM") == 259459200
assert rank("VISAKHAPATNAM") == 249207263 A hint
arrangements is n! divided by k! for each letter that appears k times (collections.Counter counts the letters). For rank, walk through the word from the left. At each position, every unused letter that comes before the letter actually there starts a block of smaller words: take that letter out of the remaining letters, add the number of arrangements of what is left, and put the letter back. The rank is the total of these blocks plus 1.
Results of the sample tests
| Test | Result | Details |
|---|
What your code printed
The sample tests run on this device, in your browser (Pyodide): nothing is sent to mysmartcopilot.com. The first run downloads Python (about 13.5 MB), which is kept for the next runs. A check in your browser is feedback for you, not proof that the code is right for every input.
Ten untimed questions on arrangements
10 questions about this lesson. Every answer and why it is right is on the page, behind “Show the answer”. Your score stays in this browser.
Ten harder arrangement items with full working, and the trap in each Pro: opens with a Pro, Premium or Ultimate pass
Harder arrangement items join two conditions: a digit rule with a range, repeated letters with a position rule, or a round table with a pattern. The ten original items below are worked in full, and each ends with the answer a hurried solver most often gives.
In this part:
- Digits with a range or a divisibility rule, worked
- Vowels kept together, and vowels in fixed places
- Round tables with a pattern, and necklaces
- A rank with repeated letters, and the sum of many numbers
- Order without adjacency, and gaps for identical letters
1 runnable example (Python) · about 4 minutes
Opening this part with your pass…
This part opens with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so this part can’t be opened at the moment. The free part above stands on its own. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
Why the formulas hold, and the two places they break Pro: opens with a Pro, Premium or Ultimate pass
Each arrangement formula is a short argument, and knowing the argument is what lets you adapt a formula when an item changes. This part proves the three that matter most, reproduces the two cases where a formula gives a wrong count, and measures how quickly n! grows.
In this part:
- Identical letters divide: a proof by labelling
- Turns and flips: round tables, necklaces and where the formula fails
- Two readings of “not together”, reproduced
- How fast n! grows, in numbers
1 runnable example (Python) · about 3 minutes
Opening this part with your pass…Pro part. It opens with the same pass as the part above.
A 12-minute set of ten items, with answers and a rubric Pro: opens with a Pro, Premium or Ultimate pass
Ten items cover every method of the lesson, at a little over a minute each. Start a 12-minute timer and work all ten before reading the answers, which follow with their working and a rubric for your score.
In this part:
- Ten mixed items, 12 minutes
- The answers, each with its shortest working
- What your score says, as a rubric
1 runnable example (Python) · about 3 minutes
Opening this part with your pass…Pro part. It opens with the same pass as the part above.
Interview questions
-
Fresher · Warm-up
Why is 0! equal to 1, and where does that matter when you count arrangements?
n! counts the orders of n different objects, and there is exactly one way to arrange nothing: leave it as it is. The formulas need that value too. nPr = n!/(n − r)! must give n! when r = n, which works only if 0! = 1; and the rule n! = n × (n − 1)! gives 1! = 1 × 0!, so 0! = 1 again. It matters whenever a formula divides by a factorial that can be 0!: arranging all 4 letters of PUNE is 4P4 = 4!/0! = 24 ways, and a word whose letters all appear once divides by 1! for each letter, which changes nothing. Taking 0! as 0 would make these formulas divide by zero.
-
Fresher
Eight guests sit at a round table, and two of them refuse to sit side by side. Count the seatings in two independent ways, and explain how the count changes if one chair is marked as the head of the table.
-
Fresher
Find the rank of KOLKATA among its different arrangements in dictionary order. Explain the method, the step that most often goes wrong with repeated letters, and a quick check that your rank is possible.
-
Fresher
How many four-digit even numbers with four different digits can be made from 0, 1, 2, 3, 4 and 5? Explain why the count must be split into cases, and how you would check it.
Key takeaways
- Multiply when one choice follows another; add when the cases are separate.
- nPr = n!/(n − r)!, and with repetition allowed there are nʳ arrangements.
- Identical items divide the count: n!/(p! q! …).
- Together: glue the group into one unit. Apart: subtract the together count, or use the gaps.
- A round table has (n − 1)! seatings and a necklace (n − 1)!/2, for three or more beads.
- A word’s rank counts the words that start with smaller letters, one position at a time.
References
- Mathematics, Class 11, Chapter 6: Permutations and Combinations (National Council of Educational Research and Training (NCERT))
- NIST Digital Library of Mathematical Functions, §26.2: Basic Definitions (National Institute of Standards and Technology (NIST))
- NIST Digital Library of Mathematical Functions, §26.4: Multinomial Coefficients (National Institute of Standards and Technology (NIST))
- Mathematics for Computer Science, chapter 15: Cardinality Rules (the division rule and round tables) (Massachusetts Institute of Technology (MIT))
- itertools.permutations (Python Software Foundation)
- math.perm and math.factorial (Python Software Foundation)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress