Find Number of Compatible Substrings
Amazon's product recommendation system aims to suggest relevant products to customers based on their recent purchase history. To achieve this, we need to identify substrings within a customer's purchase history that can be formed by concatenating all the available products in any order. We refer to such substrings as "compatible" substrings.
A substring of the purchase history is considered "compatible" if it can be formed by concatenating all the available products in any order, regardless of the order of concatenation.
Given n products, string history, and an array of string products, find the number of compatible substrings of history.
Note:
products are of equal length.products might contain duplicate products as well. In that case, each of the products (including duplicates) must be concatenated exactly once in any order as per the above rule.
Complete the function findNumberOfCompatibleSubstrings in the editor.
findNumberOfCompatibleSubstrings has the following parameters:
String history: the purchase historyString[] products: an array of product strings
Returns
int: the number of compatible substrings