Editorial for Back To School '19: H🅰️r🅰️mbe


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: Zeyu

We can loop through all the words and keep a running maximum of the longest string. If the current string is longer than the current maximum, update the best word to the current string.

To check for validity, remove the words that are greater in length than the word being replaced.

Time Complexity: \mathcal{O}(N)


Comments

There are no comments at the moment.