A content feed shows posts in order, each with a quality score in scores. For a "you'll like these less" hint, the app needs, for every post, how many posts after it have a strictly lower score.
Write lowerAfter(scores) that returns an array counts where counts[i] is the number of indexes j > i with scores[j] < scores[i]. Aim for O(n log n).
Input: scores = [5,2,6,1] Output: [2,1,1,0]
After 5 come 2 and 1 (2 lower); after 2 comes 1; after 6 comes 1; nothing comes after 1.
Input: scores = [-1,-1] Output: [0,0]
Equal scores don't count.
0 <= scores.length <= 100000-10^4 <= scores[i] <= 10^4Run 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 #194 Lower Scores Later in the Feed. 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.