I have two 2D arrays of ints and are the same length, but they are very large. I want to find if there exists at least one difference between the two arrays.
Note: I don't need to find out what the differences are, I just need to return true if there is at least one difference else false.
Right now I'm using two for loops to iterate through the indices and check if arr1[i][j] !== arr2[i][j], but this is taking over 60 seconds worst case due to size.
Is there a better way to make this comparison?
As long as you maintain the data structures in question (nested arrays), you can't get any faster than this, you have to check every element in general.
A few particular optimizations that you may conditionally apply however:
I'm fairly certain that flat arrays are faster to index, and you can use i * width + j to maintain your accesors similar, though obviously not identical.
If one of the arrays doesn't change often, and is so a reference you're checking against, you'll likely get very good results by hashing. You store the hash of your reference array every time you change it (again, it has to not be often), and every time you need to run your check against a new array you can hash he tested array and check it against the other calculated hash. Note that this can give false positives, so if the hashes match you need to actually check every element to make sure it actually is an equality.
And note that the above aren't either-or, implementing both will give you very good results!