IBM Coding Question – Solved

9 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.

Asked in: IBM

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |