Two patterns are given, one for each user. Find the longest repeating pattern for both users.
User1: ["hi", "bye", "hello", "leetcode", "start", "end"]
User2: ["hi", "stop", "leetcode", "start", "end", "bye"]
Output: ["leetcode", "start", "end"]Only solution I could think of is O(nm). Simply iterate through each string in first user and check if you find a match in the second user. What's a better way to go about this? Couldn't find a similar problem in leetcode.
Edit
Found similar problem: https://leetcode.com/discuss/interview-question/963852/Wayfair(karat)-or-OA-or-Find-longest-matching-url-visits