Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Is there a computationally efficient way of check if there exists difference(s) between two nested arrays?

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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:

  1. 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.

  2. 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!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda