Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: How many distinct strings formed by permuting the letters of "aab" are palindromes?
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
The distinct arrangements of 'aab' are aab, aba and baa; only 'aba' reads the same backwards. Counting raw permutations of the three positions (six) overstates the distinct strings.
More Coding Interview Problems questions
- Problem: Find the length of the shortest substring of "bbaac" that contains both letters 'a' and 'b' at least once.
- Problem: What is the length of the longest substring of "aabbcbbcc" in which every character occurs at least twice?
- Problem: In how many ways can 15 be written as a sum of distinct odd positive integers (order does not matter)?
- Problem: How many non-decreasing strings of length 4 over the digits {0, 1, 2} exist (each digit is at least the one before it)?
- Problem: Can the array [1, 5, 11, 5] be split into two subsets with equal sums? Answer 1 for yes and 0 for no.
- Problem: A wooden stick of length 7 must be cut at the marked positions 1, 3, 4 and 5 (measured from one end). Each cut costs the current…