I have added code file along with sample input and output files
The code takes two parameters input and output file which the user has to write after '-i' and '-o' keywords respectively.
Keeping in mind the time and space constraints given, I have used numpy array vectorization to make code time efficient as it takes much less time as compared to python loops.