PhonePe Machine Coding Question

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2023-06-22Added By Anonymous
Source:Β Link
🧭 Experience: unknown
βœ… Outcome: unknown
πŸ’° Compensation: unknown
πŸ“ Location: unknown
🏒 Company: PhonePe
πŸŽ“ Education: unknown
🎁 Benefits: unknown
πŸ“… Offer Date: unknown

**Parallel System** It’s a system that is able to give all the similar sentences for a given sentence. The system is given synonym word pairs, and at any point the system can be asked for all the synonym sentences for a given sentence. The system is expected to give these sentences, as fast as possible. Problem Statement You need to design a system that is able to give synonym sentences. There are 3 parts to this problem statement. addSynonymPair, deleteSynonymPair and getSentences. When a synonym is added or deleted, you will be provided word pairs that are synonym of each other. When sentences are being retrieved, you will be provided with a sentence, for which similar sentences need to be returned. The following is a guide for the interfaces you may have in your system. Your code might not have the same function syntax and parameters, but it should be capable of providing all the below requirements. 1- An interface to add synonym pair of words. void addSynonymPair (String word1, String word2); where, word1 = first word from the synonym pair word2 = second word from the synonym pair 2- An interface to remove synonym pairs of words. void removeSynonymPair (String word1, String word2) where, word1 = first word from the synonym pair. word2 = second word from the synonym pair. 3- An interface to get similar sentences. List<String> getSentences(String sentence) where, sentence = sentence for which unique similar sentences need to be returned in lexicographically sorted manner. Sample The following is just a sample for your understanding. Please remember: You are expected to write the system which mirrors production quality code, rather than just implementing these functions Examples for add/remove synonyms and getting sentences addSynonymPair("hello", "hey"); addSynonymPair("world", "earth"); addSynonymPair("planet", "earth"); addSynonymPair("planet", "planet"); getSentences("hello world") Output: hello earth hello planet hey earth hey planet hey world getSentences("world earth") Output: earth earth earth planet earth world planet earth planet planet planet world world world world planet removeSynonymPair("planet", "earth"); getSentences("hello world") Output: hello earth hey earth hey world Requirements P0 Implement the above with appropriate assumptions for the example shown above. Optimize your solution for time/space complexity taking reasonable tradeoffs. You can simulate the operations of adding synonyms and getting similar sentences as shown in the sample, using a main function or test cases You should have a working code that demonstrates the same. Handle error scenarios appropriately Requirements P1 Handle concurrency cases for different scenarios. Black list a word, in this case all the synonym pairs involving that word will become inactive. Things to keep in mind You are only allowed to use in-memory data structures. You are NOT allowed to use any databases. You are NOT required to have a full-fledged web service or APIs exposed. A working code is ABSOLUTELY NECESSARY. Evaluation will not be done if your code is not running. So ensure you time yourselves accordingly. You are required to showcase the working of the above concept. Just a main class that simulates the above operations is enough. Should you have any doubts, you are allowed to make appropriate assumptions, as long as you can explain them during the evaluation. You are allowed to code on your favorite IDEs as long as you paste the code back into the tool within the allotted time frame How you will be evaluated You are expected to write production quality code while implementing the requirements. We look for the following: Separation of concerns Abstractions Application of OO design principles Testability Code readability Language proficiency [execution time limit] 3 seconds (java) [memory limit] 1 GB
Comments