K-Repetitiveness Feature Value
Learn this problemProblem statement
The team of machine learning scientists at Amazon wants to improve Amazon's product recommendation system. Based on a user's purchase history, the objective is to generate some extensive features that will be given as input to the machine learning model. One of the new proposed features is a k-repetitiveness feature whose computation is described below.
The purchase history of a user with the products available on Amazon is available in the form of a string user_history where the ith character represents the category of the ith product purchased by the user. The length of string user_history is n. There is also a given integer k.
The value of the k-repetitiveness feature for the string user_history is defined as the maximum number of substrings of the given string such that some product category in that substring appeared at least k times.
Find the value of the k-repetitiveness feature for the given string user_history.
Note: A substring is a continuous subsegment of a string.
Function
getkRepValue(user_history: String, k: int) → int
Complete the function getkRepValue in the editor.
getkRepValue has the following parameters:
String user_history: the interaction history of the userint k: the minimum occurrence of a product for a substring to be included in the k-repetitiveness feature
Returns
An integer denoting the value of the k-repetitiveness feature.
꒰ა 🌷, Credit to Suat ᡣ𐭩♫⋆。♪˚♬ ゚໒꒱
Examples
Example 1
user_history = "ceccca"k = 3return = 7
Example 2
user_history = "acaab"k = 3return = 2Constraints
- 1 ≤ length of
user_history≤ 5 · 10^4 - 1 ≤ k ≤ 5 · 10^4
- The string
user_historyonly contains lowercase Latin letters, ascii[a-z].
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026