You are given two lists and both containing the numbers in some order. Your task is to count how many of the numbers occur earlier on the list than on the list .
In this task, can be large and an efficient algorithm is required. The time complexity should be .
In a file twolists.py
, implement a function count
that returns the desired count.
def count(a, b): # TODO if __name__ == "__main__": print(count([2,3,4,1], [1,2,3,4])) # 3 print(count([1,2,3,4], [1,2,3,4])) # 0 print(count([4,7,3,1,6,2,5], [5,6,1,2,4,3,7])) # 3 print(count([5,4,9,1,8,3,2,6,7], [6,2,8,4,9,1,5,7,3])) # 5
Explanation: In the first test, the numbers 2, 3 and 4 occur earlier on the list than on the list .