Editorial for Speech

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.

A simple way of approaching this problem is storing the entire string as an array, with the indexes being words. For loop each friendly-unfriendly pair to check the entire string array, and replace all words that match the unfriendly word. Remember to strip out the period and add it back in after the for loop executes. The Time complexity can be reduced by using dictionaries or other data structures.

Skills needed: Array manipulation, string manipulation, for loops

Time complexity: \mathcal O(NM), where M is the number of words in the string.


There are no comments at the moment.