Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: What is the minimum number of characters to delete from "programming" so that all remaining characters are distinct (keep one copy of each letter)?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Keeping one copy of each distinct letter needs deletions equal to the length minus the number of distinct letters. Counting only the repeated letters' duplicates misses multi-copy letters with more than two occurrences.
More Coding Interview Problems questions
- Problem: Compute the longest palindromic prefix of "abacabacaba" (the longest prefix that reads the same backwards). What is its length?
- Problem: What is the length of the longest common substring (contiguous) of "abcdxyz" and "xyzabcd"?
- Problem: From the array [3, 2, 7, 10], choose a subset with no two adjacent indices chosen, maximising the sum. What is the maximum sum?
- Problem: The array [5, 1, 6, 2, 7] must be made strictly increasing by deleting the fewest elements. What is the minimum number of…
- Problem: On the complete graph K4 (vertices 0–3, every pair adjacent), how many walks of exactly 4 edges start at vertex 0? A walk may…
- Problem: Lomuto partition uses the last element as the pivot on [3, 8, 2, 5, 1, 4, 7, 6]. After one partition pass, at what index…