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?
- A. 231
- B. 223
- C. 627
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the length of the longest subsequence of [1, 7, 4, 9, 2, 5, 3, 8] whose consecutive differences alternate in sign (each step goes…
- How many contiguous subarrays of [1, 2, 3, 4, 7, 10, 13, 14, 15, 16] are arithmetic (at least 3 elements, with a constant difference…
- What is the length of the longest contiguous substring of the binary string "1100100110111000101" that has equally many 0s and 1s?
- What is the smallest positive period p of the string abcabcabca, meaning the smallest p such that s[i] = s[i+p] for every valid i?
- How many distinct cyclic rotations does the string abcabc have (rotations are the strings obtained by moving a prefix to the end…
- How many subarrays of [1, 2, 1, 2, 2, 1] read the same forwards and backwards (as sequences of values)?