Data Structures & AlgorithmsHardCAT · TCS NQT
Problem: The number of permutations of the digits 1, 2, 3, 4 in which the digit 1 is not in the first position and 4 is not in the last position is what value?
- A. 12
- B. 14
- C. 18
- D. 24
Correct answer: B. 14
Inclusion-exclusion: 24 − 6 − 6 + 2 = 14. Forgetting to add back the 2 permutations with both gives 12, applying only one restriction gives 18, and 24 ignores both.
More Coding Interview Problems questions
- Problem: Cars pass a toll booth at times 2, 5, 6, 10, 11, 15 (minutes). A car may pass only if at least 3 minutes have elapsed since the…
- Problem: A sorted list of distinct integers is 3, 8, 12, 17, 21, 26, 30. How many pairs (i < j) have a[j] − a[i] exactly equal to 9?
- Problem: The value of 3^(3^3) mod 7 is what?
- Problem: A path graph has vertices 1–6 with edges between consecutive vertices. How many pairs of vertices are at distance exactly 2?
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→4, 4→2, 1→5. Starting from 1, how many distinct vertices are reachable…
- Problem: In the array [9, 2, 6, 4, 7, 1], what is the number of elements that are smaller than every element to their left (strict left…