## Editorial for SAC '22 Code Challenge 5 Junior P5 - English Summative

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Author:

##### Subtask 1

It suffices to iterate over all possible subsets of the words and count the number of consecutive pairs of letters.

**Time Complexity:**

##### Subtask 2

Realize that this problem can be modelled with dynamic programming:

represents the maximum number of consecutive pairs of letters that ends at the word.

The recurrence of is , where , , is the first character of the word, is the last character of the word, and is the number of consecuive pairs of letters in the word.

Finally, output .

**Time Complexity:**

##### Subtask 3

Realize that subtask 2 can be greedily optimized by only maintaining the index of the last lowercase letters and the maximum value for that character.

**Time Complexity:**

## Comments