A review page lists every rating of a product in ratings, sorted from lowest to highest, so equal ratings sit next to each other. A filter chip needs to highlight all ratings equal to target.
Write ratingSpan(ratings, target) that returns [first, last]: the first and last index holding target. If target is not in the list, return [-1, -1].
Use O(log n) time.
Input: ratings = [1,2,4,4,4,5], target = 4 Output: [2,4]
The 4s sit at indexes 2, 3, and 4.
Input: ratings = [1,2,4,4,4,5], target = 3 Output: [-1,-1]
No rating is 3.
0 <= ratings.length <= 100000ratings is sorted ascending.-10^9 <= ratings[i], target <= 10^9Run 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 #156 Span of a Repeated Rating. 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.