Follower count ranges
Write code · Medium · §8.1 Searching a sorted list
followers holds the number of followers of each account. The follower counts are in no particular order.
ranges holds the follower ranges that advertisers are looking for. An element [lo, hi] of ranges means the advertiser wants accounts with at least lo and at most hi followers. Complete the function solution, which returns a list of how many such accounts there are for each condition, in the same order as ranges.
Function
solution(followers, ranges)
Constraints
- The length of
followersis from 1 to 500,000, and each element is an integer from 0 to 1,000,000,000. - The length of
rangesis from 1 to 20,000. - Each element of
rangeshas the form[lo, hi], whereloandhiare integers from 0 to 1,000,000,000 andlois at mosthi.
Examples
| followers | ranges | result |
|---|---|---|
[27000, 9900, 1500, 780, 5200, 15000, 560] | [[5000, 25000], [3000, 8000]] | [3, 1] |
[1300, 220, 900, 480, 150] | [[200, 700], [300, 2300]] | [2, 3] |
Starter code
def solution(followers, ranges):
answer = []
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.