Posts at or above the bar
Write code · Basic · §8.1 Searching a sorted list
likes holds the number of likes on each of one person's posts, in ascending order. Several posts may have the same number of likes.
A "Popular" badge goes on posts whose likes reach a certain bar, and the candidate bars are collected in goals. Complete the function solution, which returns, for each bar in goals, the number of posts with at least that many likes, as a list in the same order as goals.
Function
solution(likes, goals)
Constraints
- The length of
likesis from 1 to 100,000, and its elements are in ascending order. - Each element of
likesis an integer from 0 to 1,000,000,000. - The length of
goalsis from 1 to 10,000, and each element is an integer from 0 to 1,000,000,000.
Examples
| likes | goals | result |
|---|---|---|
[3, 8, 15, 22, 40] | [10, 20] | [3, 2] |
[0, 5, 5, 9] | [6, 1] | [1, 3] |
Starter code
def solution(likes, goals):
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.