Data Structures & AlgorithmsVery hardTCS NQT Digital · Product Company SDE
Problem: Among all distinct permutations of the letters A, B, C, D, arranged in dictionary order starting from rank 1, what is the rank of "CADB"?
- A. 13
- B. 16
- C. 11
- D. 14
Correct answer: D. 14
C has 2 smaller remaining letters (2 · 3! = 12), A has 0, D has 1 smaller remaining letter (1 · 1! = 1), so 13 permutations precede CADB and its rank is 14. Forgetting the + 1 gives 13, counting smaller letters overall instead of among the remaining (3 for D) gives 16, and ranking from the end of the list (24 − 14 + 1) gives 11.
More Coding Interview Problems questions
- Problem: For the words ["flowchart", "flow", "flight", "flower"], what is the length of their longest common prefix?
- Problem: In the string "abciiidef", what is the maximum number of vowels (a, e, i, o, u) in any contiguous substring of length 4?
- Problem: What is the minimum number of insertions plus deletions needed to convert "heap" into "pea" if only insertions and deletions are…
- Problem: How many binary strings of length 8 have no two consecutive 1s and begin with the digit 0?
- Problem: A 0/1 knapsack has capacity 10 and items (weight, value): (5, 10), (4, 40), (6, 30), (3, 50). What is the maximum total value?
- Problem: The longest bitonic subsequence (first strictly increasing, then strictly decreasing, either part may be empty) of [1, 11, 2, 10…