Loading...
Loading...
Loading...
Two reports each list customer ids in increasing order with no repeats. Print how many ids appear in both reports. Comparing every id of one report with every id of the other is too slow.
Example
Input
5 4 101 102 103 104 105 104 105 106 107
Output
2
Try the problem first. Open one hint at a time.
The nested loop does n × m comparisons.
Both lists are sorted, so two pointers walk them once; a set intersection also works in O(n + m).
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor