As we can not update all the strings that have prefix PPfor each update query, we can hold the update for the time when it is required. That requires lazy propagation on trie. The idea is to save the information of the trie node which holds the last character of the given prefix to the node which holds the updated last character. whenever you visit a node of a trie, you just propagate lazily.

Time complexity: O(sum of characters * 26)

Statistics

83% Solution Ratio
samiulsamiEarliest, Dec '21
Kuddus.6068Fastest, 0.1s
nusuBotLightest, 330 MB
serotoninShortest, 1524B
Toph uses cookies. By continuing you agree to our Cookie Policy.