Split Prefix Suffix
Learn this problemProblem statement
Amazon Prime Day is a day where many items are put on sale for Amazon Prime members. A list of sale items is assembled where each item is assigned a category denoted by a lowercase English letter.
Since the sale is to be held on two different days, the company has decided to split the list of items into two contiguous non-empty sub-lists - a prefix and a suffix. To ensure that both days share a sufficient number of similar items, they also need to split it in a way such that the number of distinct categories shared by both sub-lists is greater than k.
Formally, given a string, categories, find the number of ways to split the string into exactly two contiguous non-empty substrings such that the number of distinct characters occurring in both the substrings is greater than a given integer k.
Function
splitPrefixSuffix(categories: String, k: int) → int
Complete the function splitPrefixSuffix in the editor.
splitPrefixSuffix has the following parameters:
string categories: the categoriesint k: shared distinct categories must be greater than this value
Returns
int: the number of ways to split the given string
Examples
Example 1
categories = "abbcac"k = 1return = 2
Constraints
1 ≤ length(categories) ≤ 10^50 ≤ k ≤ 26- The string
categoriesconsists of lowercase English characters.
More 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