# Probability and counting: GATE CS question with solution

From the GATE Daily set of 26 October 2026, question 1 of 10 (https://gatedaily.in/q/2026-10-26-books-on-shelf-two-forbidden-positions/). Difficulty: standard.

### Q.1 · General Aptitude · Probability and counting · MCQ, 1 mark (choose one option)

Five different books $P$, $Q$, $R$, $S$ and $T$ are to be placed in a single row on a shelf. In how many of the arrangements is book $P$ **not** in the leftmost position and book $Q$ **not** in the rightmost position?

(A) 72
(B) 78
(C) 96
(D) 120

**Answer:** (B) 78

**Solution.** **Method: count the complement with inclusion-exclusion.**

All arrangements: $5! = 120$.

Let $A$ = arrangements with $P$ leftmost and $B$ = arrangements with $Q$ rightmost.

- $|A| = 4! = 24$ (fix $P$, arrange the other four).
- $|B| = 4! = 24$.
- $|A \cap B| = 3! = 6$ ($P$ leftmost **and** $Q$ rightmost, arrange the middle three).

Bad arrangements: $|A \cup B| = 24 + 24 - 6 = 42$. Good arrangements: $120 - 42 = 78$.

**Check by direct counting.** If $P$ is rightmost, $Q$ cannot be rightmost, so the other four go anywhere: $4! = 24$. If $P$ is in one of the three middle positions, $Q$ has 3 allowed positions out of the remaining 4, and the other three books fill the rest in $3!$ ways: $3 \times 3 \times 6 = 54$. Total $24 + 54 = 78$.

**Trap.** Subtracting $24 + 24$ from 120 gives 72: the 6 arrangements that break both rules were removed twice and must be added back once. Applying only one rule gives 96.

**What was tested:** turning "not this and not that" into a complement and applying two-set inclusion-exclusion correctly.

**Remember:** For "none of the forbidden events", count total minus the union, and compute the union as $|A| + |B| - |A \cap B|$. Forgetting the overlap term is the usual slip.

**Why each option:**
- (A) Subtracts both restricted cases (24 + 24) but forgets to add back the 6 arrangements counted in both.
- (B) 120 - (24 + 24 - 6) = 78 by inclusion-exclusion.
- (C) Enforces only one restriction: 120 - 24 = 96 keeps P out of the leftmost position but lets Q be rightmost.
- (D) Ignores both restrictions and counts every arrangement of five books.
