A crypto ticker shows a streak badge each day: how many days in a row, ending today and counting backwards, the price was less than or equal to today's price. Write a class PriceStreak:
new PriceStreak() starts with no days.next(price) adds today's price and returns today's streak. Today always counts, so the streak is at least 1.Each example lists the calls in order, then each call's arguments. The first call creates the object with new PriceStreak(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["PriceStreak","next","next","next","next","next","next","next"] [[],[100],[80],[60],[70],[60],[75],[85]] Output: [null,1,1,1,2,1,4,6]
On the 75 day the prices 75, 60, 70, 60 are all at most 75, so the streak is 4. 85 covers six days.
Input: ["PriceStreak","next"] [[],[10]] Output: [null,1]
A single day has a streak of 1.
1 <= price <= 10^510^4 calls.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #266 Price Streak Tracker. 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.