🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 63 - 100% Working Solution | Buy Now
Description
6 Live
In an e-commerce product search system, users input queries to search for items. You are given an array products of length n representing the product names and an array queries of length q containing search query strings.
Implement a function that, for each query string, returns all products that are anagrams of the query string. An anagram is any string that can be formed by rearranging the letters of another string.
The function getProductMatches takes the following inputs:
string products[n]: the list of all available product names
string queries[q]: the list of search query strings
The function should return a list of products for each query that are anagrams of the query string, sorted alphabetically.
Example
Input:
n = 4
products = ["duel", "speed", "dule", "cars"]
q = 2
queries = ["spede", "deul"]
Output:
["speed"]
["duel", "dule"]
Explanation:
For queries[0] = "spede", the only anagram of "spede" is "speed", so the answer for this query is ["speed"].
For queries[1] = "deul", the anagrams in the product list are "duel" and "dule", so the answer for this query is ["duel", "dule"].
The function getProductMatches should return a list of lists, where each inner list contains the matching anagram products for a given query, sorted alphabetically.