UPSC CSAT 2022 Q55: Counting Lock PINs with Digit Gaps — Solved

There is a numeric lock which has a 3-digit PIN. The PIN contains digits 1 to 7. There is no repetition of digits. The digits in the PIN from left to right are in decreasing order. Any two digits in the PIN differ by at least 2. How many maximum attempts does one need to find out the PIN with certainty?

  1. 6
  2. 8
  3. 10
  4. 12

Answer: (c) 10

Solution

  1. Turn the conditions into a counting rule. The PIN uses 3 different digits from 1 to 7. They are written in decreasing order. So once you choose the 3 digits, there is only one way to arrange them. Counting PINs is the same as counting sets of 3 digits.
  2. Apply the gap condition. Any two digits must differ by at least 2. Write the PIN as a > b > c. If a − b ≥ 2 and b − c ≥ 2, then a − c ≥ 4 automatically. So you only need to check the two neighbouring gaps.
  3. Case: smallest digit c = 1. - b = 3: a must be ≥ 5, so a = 5, 6, 7. That gives 531, 631, 731 (3 PINs). - b = 4: a ≥ 6, so a = 6, 7. That gives 641, 741 (2 PINs). - b = 5: a ≥ 7, so a = 7. That gives 751 (1 PIN). - b = 6 would need a ≥ 8, which is not allowed. - Subtotal: 3 + 2 + 1 = 6.

  4. Case: c = 2. - b = 4: a = 6, 7. That gives 642, 742 (2 PINs). - b = 5: a = 7. That gives 752 (1 PIN). - Subtotal: 2 + 1 = 3.

  5. Case: c = 3. - b = 5: a = 7. That gives 753 (1 PIN). - Subtotal: 1.

  6. Case: c = 4 or more. You would need b ≥ 6 and a ≥ 8. This is impossible, so there are 0 PINs here.

  7. Total possible PINs: 6 + 3 + 1 = 10. The full list is 531,631, 731, 641, 741, 751, 642, 742, 752, 753.
  8. Worst case. To be certain, assume the correct PIN is the last one you try. That means up to 10 attempts.

Answer: 10

Option-wise explanation

  • a: incorrect — 6 counts only the PINs whose smallest digit is 1 (531, 631, 731, 641, 741, 751). It misses 642, 742, 752 and 753, where the smallest digit is 2 or 3. The trap is stopping after the first case.
  • b: incorrect — 8 comes from an incomplete list, for example missing two of the c = 2 or c = 3 PINs such as 742 or 753. A full case-by-case count of the smallest digit gives 6 + 3 + 1 = 10, not 8.
  • c: correct — There are exactly 10 valid sets of digits: 6 with smallest digit 1, 3 with smallest digit 2, and 1 with smallest digit 3. In the worst case the right PIN is the tenth one you try, so 10 attempts guarantee success.
  • d: incorrect — 12 is an overcount. It comes from letting a gap of 1 slip in (for example accepting 732 or 643) or counting one PIN twice. Every listed PIN must have both neighbouring gaps of at least 2, and only 10 do.

How to eliminate

  • Fix the smallest digit at 1 and count first. You get 3 + 2 + 1 = 6 quickly. 753 and 642 are clearly valid too, so the answer is more than 6, which rules out 6 at once.
  • The counts per case fall in a triangle: 3 + 2 + 1 for c = 1, then 2 + 1 for c = 2, then 1 for c = 3. That is 6 + 3 + 1 = 10, which leaves only 10 among 8, 10 and 12.
  • Shortcut if you know it: squeeze out the gaps. Subtract 2 from the largest digit and 1 from the middle digit. You now need any 3 distinct digits from 1 to 5, and C(5, 3) = 10.
  • "Maximum attempts with certainty" means the worst case, so the number of attempts equals the number of possible PINs.

About 60–90 seconds by listing, or 20 seconds with the gap-squeeze formula. Attempt this question first: it is short, it involves no heavy arithmetic, and it can be checked by listing.

Know more

Choosing numbers with a minimum gap

If the order is fixed (increasing or decreasing), counting arrangements is the same as counting selections. To choose k numbers from 1 to n so that neighbouring choices differ by at least g, squeeze out the extra gaps:

  • Keep the smallest number as it is. Subtract (g − 1) from the next one, 2(g − 1) from the one after, and so on.
  • The gap condition becomes simply "distinct", and the range shrinks to 1 to n − (k − 1)(g − 1).

Count = C(n − (k − 1)(g − 1), k)

For this question: n = 7, k = 3, g = 2, so the count is C(7 − 2, 3) = C(5, 3) = 10.

Worked variant: choose 4 digits from 1 to 8 with neighbouring gaps of at least 2. Count = C(8 − 3, 4) = C(5, 4) = 5. Check by listing: 1357, 1358, 1368, 1468, 2468.

n (digits 1..n) k chosen gap ≥ g Count
7 3 2 C(5,3) = 10
9 3 2 C(7,3) = 35
8 4 2 C(5,4) = 5
9 3 3 C(5,3) = 10

Common slips: forgetting that a fixed order removes the factor of k!, stopping after the first case of the smallest digit, and checking only one of the two gaps.

Two things to keep from this question: "maximum attempts with certainty" means the worst case, which equals the total count, and when the options are close, list the cases to check the formula.