Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: A set of letters {A, B, C, D, E} is arranged in a row. How many arrangements have A immediately to the left of B?
- A. 48
- B. 24
- C. 120
- D. 60
Correct answer: B. 24
Glue AB into one block (order fixed): 4! = 24 arrangements. Allowing BA too gives 48, 120 counts all arrangements, and 60 counts A anywhere to the left of B.
More Coding Interview Problems questions
- Problem: The number of ways to split a line of 6 people into 2 groups of 3 (groups are distinguishable by their first member, so each…
- Problem: The string "racecar" is compared with its reverse position by position. How many positions have matching characters?
- Problem: Starting with the number 1, double it and add 1 repeatedly. What is the value after the 10th doubling step (starting value 1, 10…
- Problem: The array [2, 4, 3, 1, 6, 5] is partitioned into the largest possible number of consecutive chunks such that after sorting each…
- Problem: A string of length 4 over {0, 1} has an even number of 1s. How many such strings are palindromes?
- Problem: The product 2^3 · 3^2 · 5^1 · 7^2 has how many positive divisors?