Data Structures & AlgorithmsModerateCAT · TCS NQT Digital
Problem: How many 4-digit numbers (1000 to 9999) have all four digits distinct and in strictly decreasing order from left to right?
- A. 126
- B. 714
- C. 210
- D. 5040
Correct answer: C. 210
Any 4 distinct digits can be arranged in exactly one decreasing order, and 0 can only be last, so the count is C(10, 4) = 210. Excluding 0 gives C(9, 4) = 126, allowing equal neighbours gives 714, and 5040 counts all ordered distinct-digit choices.
More Coding Interview Problems questions
- Problem: Compute the sum of the digits of the number 2^20 × 5^18 written in decimal.
- Problem: Let f(n) = number of 1-bits in n. Compute Σ f(n) for n from 0 to 63 inclusive.
- Problem: Starting at (0,0), the robot moves in the string "NNEESSWWNE" with N = up, E = right, S = down, W = left. Count the number of…
- Problem: The sequence a1 = 2, and each next term is a(n+1) = (a(n) × 3 + 1) mod 11. What is a(20)?
- Problem: A bag holds coins of values 1, 4 and 9. You must pay exactly 30 using as few coins as possible. What is the minimum number of…
- Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down…