Data Structures & AlgorithmsVery hardCodeforces Div2 D

You may delete characters from "sea" and from "eat" to make the two strings equal. Deleting a character costs its ASCII code (for example 'a' costs 97). What is the minimum total cost?

  1. A. 231
  2. B. 223
  3. C. 627
  4. D. 332

Correct answer: A. 231

This is an LCS with weights: keep matching letters for free and delete the rest at their ASCII cost. Plain LCS (counting only the number of deleted letters) minimises the count, not the cost, so it can pick a more expensive kept set.

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

Exams that ask this topic