Data Structures & AlgorithmsVery hardCAT · ICPC regional
Problem: The number of ways to arrange the letters of "LEVEL" so that the two E's are not adjacent is what value?
- A. 30
- B. 12
- C. 72
- D. 18
Correct answer: D. 18
LEVEL has 5!/(2!·2!) = 30 distinct arrangements; gluing the E's gives 4!/2! = 12, so 30 − 12 = 18. 30 ignores the rule, 12 counts the adjacent ones, and 120 − 48 = 72 forgets the repeated letters.
More Coding Interview Problems questions
- Problem: Consider the sequence 1, 4, 9, 16, … of perfect squares. What is the smallest square that is greater than 500 and also ends in…
- Problem: How many 4-letter strings over {A, B, C} have no letter appearing more than twice?
- Problem: The binary tree with root 10, left child 5, right child 15, and 5 having right child 7, 15 having left child 12, is traversed in…
- Problem: A list starts as [8, 3, 5]. Three insertion steps add the numbers 4, 9, 1 at the front of the list (each is inserted at index 0)…
- Problem: A deque starts as [2, 4, 6]. The operations are: push front 1, push back 8, pop front, push back 3. What is the sum of the final…
- Problem: The string "tenet" is considered. How many of its substrings (by index range, length at least 2) are palindromes?