A product carousel shows k neighboring items from a feed at a time. The feed lists product prices in prices, and the same price means the same product. The marketing team wants a run of k items where every product is different and the total price is as high as possible.
Write bestDistinctRun(prices, k) that returns the largest total of k consecutive prices that are all different. If no such run exists, return 0.
Input: prices = [1,5,4,2,9,9,9], k = 3 Output: 15
[5, 4, 2] totals 11 and [4, 2, 9] totals 15. Any run with two 9s has a repeat.
Input: prices = [4,4,4], k = 3 Output: 0
The only run repeats 4.
1 <= k <= prices.length <= 1000001 <= prices[i] <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #133 Best Run of Distinct Products. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.