Your question is Common Elements in Sorted Lists. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Criteo's advertising systems compare sorted identifier sequences during audience and event-processing workflows. Given two sorted integer lists, return their common values in sorted order.
Implement intersect_sorted_lists(first, second). The inputs are lists of integers sorted in nondecreasing order. Return a new list containing each common integer as many times as it appears in both inputs. In other words, the output contains the minimum frequency from the two input lists. Do not modify either input list.
Use a two-pointer approach that takes advantage of the sorted inputs.
def intersect_sorted_lists(first, second):