Computer Science, asked by nusrath7191, 2 months ago

Amazon is building a way to help customers search reviews quicker by providing real-time suggestions to search terms when the customer starts typing. When given a minimum of two characters into the search field the system will suggest at most three keywords from the review word repository. As the customer continues to type in the reviews search bar the relevant keyword suggestions will update automatically. Write an algorithm that will output a maximum of three keyword suggestions after each character is typed by the customer in the search field. If there are more than three acceptable keywords, return the keywords that are first in alphabetical order. Only return keyword suggestions after the customer has entered two characters. Keyword suggestions must start with the characters axeady typed Both the repository and the customerQuery should be compared in a case-insensitive way.

Answers

Answered by nishasingh861991
0

Answer:

hshdhdhehrgrgr²3³$ee

Answered by aburaihana123
0

Amazon is building a way to help customers search reviews, when the customer starts typing the system will suggest three keywords.

Input :

  • The method/function receives two arguments as input: customer Query is a string that contains the entire search query entered by the customer.
  • The repository is a collection of one-of-a-kind strings that represent the numerous keywords found in Amazon's review comment section.

Output

  • Return a list of lower-case strings, where each list contains the system's keyword suggestions as the customer types each character in the customer Query.
  • Assume that the customer types the characters in the correct order, without deleting or removing any. Return an empty array if an output isn't possible

For example:

Input:

repository = ['mobile', 'mouse', 'moneypot', 'monitor', 'mousepad']

 customerQuery = 'mouse'

output:

 ['mobile', 'moneypot', 'monitor']

 ['mouse', 'mousepad']

 ['mouse, 'mousepad']

 ['mouse, 'mousepad']

Explanation:

  • The sequence of terms that will appear in the search box will be mo, mou, mous, mouse, with each line of output displaying the recommendation of'mo','mou','mous', and'mouse', respectively.
  • The following matches will be created for the keyword suggestions generated by the system for'mo': ['mobile,'mouse,'moneypot,'monitor,'mousepad']
  • They will be reordered alphabetically to [mobile, moneypot, monitor, mouse, mousepad]
  • As a result, the system's keyword suggestions are [mobile, moneypot, monitor].

Algorithm for keyword suggestion:

function searchSuggestions(repository, customerQuery) {

   if (customerQuery.length < 2) {

       return;

   }

     let search = '';

   const matchedArray =[];

   

   for (let i = 0; i < customerQuery.length; i++) {

       search = search + customerQuery.charAt(i);

       const tempMatchedArray = [];

       if (search.length > 1) {

           repository.find((string) => {

               if (string.toLowerCase().startsWith(search.toLowerCase())) {

                   tempMatchedArray.push(string.toLowerCase());

               }

           });  

       }

       if (tempMatchedArray.length > 0) {

           matchedArray.push(tempMatchedArray.sort().slice(0,3));  

       }

   }

       

   return matchedArray;

}

#SPJ3

Similar questions