I would fill a smaller array with large sizes with zero values ââ(or with NaN), convert to 1D and truncate / cut unnecessary values:
array_1 = [1, 2, null, null, 5, 6] array_2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
then compare 1D arrays, skipping zero values ââ- this will be O(n*m) in the worst case (for example, [1,1,1,2] vs [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ), and at best it will be O(n) (if each number in the larger array was different)
Edit : More logic is needed to ensure comparisons are only within the full lines of a larger array, not line by line ...
I think you could convert arrays to position dictionaries and figure out a slightly more complex and faster algorithm if you need to make a few comparisons ...
You can also rotate a smaller array if necessary, for example:
array_1_270 = [6, 2, null, null, 1, 5]