I need a proper data structure for a collection of strings. Users may query for the current number of strings in the collection that have a certain prefix or suffix, and subsequently remove these strings from the collection if they choose to. Users may also insert one string; if a string is inserted more than once, it should be returned multiple times.
The time complexity of query operations should be O(m + log n), where m is the expected size of the result of the operation.
I am thinking of using a Trie but we will have to use 2 tries one for the suffix and another for prefix, the problem with the approach is we won't be able to apply remove() in required time in that case.