The page a post is on

Write code · Medium · §8.1 Searching a sorted list

posts holds the numbers of the posts still on a message board, in ascending order. The numbers of deleted posts are not in posts. The board list shows k posts per page in the order of posts: page 1 shows posts[0] to posts[k - 1], page 2 shows the next k, and so on.

links holds the numbers of posts reached through shared links. Complete the function solution, which returns a list of the page each linked post is on, in the same order as links. If a link's number is not in posts (the post was deleted or never existed), use -1 for that link.

Function

solution(posts, k, links)

Constraints

Examples

postsklinksresult
[2, 3, 5, 8, 9, 12, 15]3[8, 15, 4][2, 3, -1]
[1, 4, 6, 7]2[1, 6][1, 2]

Starter code

def solution(posts, k, links):
    answer = []
    return answer

Solve 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.