Find Number of Compatible Substrings
Learn this problemProblem statement
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.Function
findNumberOfCompatibleSubstrings(history: String, products: String[]) → int
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
Examples
Example 1
history = "abcdefdefabcghidefabcxyz"products = ["abc", "def", "ghi"]return = 3More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026