Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: The string "BANANA" has how many distinct arrangements of its letters (letters are identical when they match)?
- A. 60
- B. 720
- C. 120
- D. 360
Correct answer: A. 60
BANANA has A × 3, N × 2, B × 1, so 6! / (3! · 2!) = 60. Ignoring repeats gives 720, dividing only by 3! gives 120, and dividing only by 2! gives 360.
More Coding Interview Problems questions
- Problem: For the word-count test: how many distinct strings can be formed by rearranging "AABBCCD" so that no two identical letters are…
- Problem: A game uses 5 players in a circle numbered 1 to 5. The player with the ball passes it 3 positions clockwise each turn (the ball…
- What does this program print? python a = [4, 1, 3, 2] best = 0 for i in range(len(a)): for j in range(i + 1, len(a) + 1): best = max(best…
- What does this program print? python n = 6 dp = [0] (1 << n) dp[0] = 1 for mask in range(1 << n): if dp[mask] == 0: continue for v in…
- What does this program print? python x = 22 cnt = 0 while x: x &= x - 1 cnt += 1 print(cnt, bin(22).count('1'))
- Array [2, 7, 4, 9, 5, 8]. What is the largest sum of a contiguous subarray having at most 3 elements?