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)?

  1. A. 4
  2. B. 3
  3. C. 2
  4. 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

Exams that ask this topic