Find Recurring Names
Learn this problemProblem statement
Amazon rewards its new users with a discount coupon that can be applied to their first purchase. Some users create more than one account in order to receive the offer multiple times. It was found that their new usernames are only a permutation of their real names.
For examples, if the real usernames of the users are realNames = ["abc", "def"] and the list of all usernames is allNames = ["bca", "abc", "cba", "def"], then the user "abc" must have made multiple accounts as there are three permutations of "abc" in the list of all usernames.
Given an array of realNames an array allNames of usernames for each account, identify the names of users who created accounts more than once. The goal is to return the array of real names of these users in lexicographical order. If there are no such names, return an array containing only the string "None".
Please note that:
realNames, each value is unique, and indicates an individual person.allNames is a permutation of some name in realNames.realNames without a permutation in allNames.Function
findRecurringNames(realNames: String[], allNames: String[]) → String[]
Complete the function findRecurringNames in the editor.
findRecurringNames has the following parameters:
string realNames[n]: the real user namesstring allNames[m]: all registered user names
Returns
string[]: the distinct real names of users with multiple registrations in lexicographical order
Examples
Example 1
realNames = ["rohn", "henry", "daisy"]allNames = ["ryhen", "aisyd", "henry"]return = ["henry"]Example 2
realNames = ["tom", "jerry"]allNames = ["reyjr", "mot", "tom", "jerry", "mto"]return = ["jerry", "tom"]Constraints
- 1 ≤ n, m ≤ 10^5
- 1 ≤ |realNames[i]|, |allNames[i]| ≤ 10
- Each name in realNames and allNames consists of lowercase English letters only.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026