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

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |