The task is, you have an array of n numbers called
nums, and an array of m numbers called
For each element in
maxes, find how many members of
nums are smaller than or equal to that element.
nums = [4, 2, 5, 10, 8] maxes = [3, 1, 7, 8] output = [1, 0, 3, 4]
The first element, 3, in
maxes, is higher than only
nums, hence the first element in output is 1.
The initial solution I could think of was trivial, and it scales as O(n²):
def sol_naive(nums,maxes): output =  for entry in maxes: higher_numbers = len([x for x in nums if x <= entry]) output.append(higher_numbers) return output
I'm wondering if there's a better approach to solve this problem.