1. Design a publish-subscribe system
Design a publish-subscribe (pub-sub) system. Explain the components involved in this system, how they interact, and what design patterns might be useful in this context. Discuss considerations for scalability and reliability.
2. Design a class to track the occurrence of errors within a window size
Design a class that tracks error occurrences within a specified window size. The class should provide two APIs: one for logging an error ID, and another for retrieving the most frequent error ID within the window. Discuss how you would implement this class and consider any object-oriented design principles that would apply.
3. Grouping 3D Points Based on Distance Threshold
Given an array of points where each point represents a 3D position, and a distance threshold 'k', write a program to determine the number of groups formed where the distance between any two points in a group is less than or equal to 'k'. Additionally, output the number of points in each group and the specific points that constitute each group.
4. Design a Data Structure with O(1) Operations
Design a data structure that supports the following operations with O(1) time complexity: add_key(), which increments the frequency of a key; dec_key(), which decrements the frequency of a key; and get_max(), which retrieves any key with the highest frequency.
5. Implement a Word Dictionary
Implement a Word Dictionary with the following functionalities:
- addWord(String word): Add a word to the dictionary. This function takes a string 'word' as an input and returns nothing.
- match(String query): Search for a word in the dictionary. The 'query' is a string that may contain lowercase alphabets or a single character wildcard. For example, if the dictionary contains the word 'apple', the query 'a.ple' should return a match.