Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B

How many ways can "abcabcdaab" be cut into a non-empty left part and a non-empty right part so that the two parts contain the same number of DISTINCT letters?

  1. A. 3
  2. B. 9
  3. C. 1
  4. D. 0

Correct answer: C. 1

Compute distinct counts of prefixes and suffixes with a scan (prefix set size grows as letters appear); each cut compares the two counts. Comparing the total letter counts instead answers a different question.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic