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

97
Visualizações
Find the largest substring combination between 2 DNA sequences and return its first character position

I have this coding challenge that I can't stop thinking about and I couldn't solve. You are given 2 strings that represent 2 DNA sequences, for example: dna1 = "ATGGTTAT" dna2 = "AGTGTTAT" The sequences sizes are the same (they can have from 7 to 8 characters) and if they have any matching substrings, you should compare them and return the first largest matching substring's position.

Example: dna1 = "AAGGTGAT" dna2 = "AATGTGAT" The output should be 3.

I tried using for loops to iterate and compare both sequences and return the position, but i can't find a way to separate the matching substrings, compare them and return the position. Is there any easy way for doing that? Or is there a better language to do this?(I used javascrip)

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

0

Since you are only comparing characters in the same position in both strings, you only need one loop:

function mm(a, b) {
    let longest = 0;
    let longestPos = -1;
    let pos = 0;
    let len = 0;
    while (pos < a.length) {
        if (a[pos] == b[pos]) {
            len++;
            if (len > longest) {
                longest = len;
                longestPos = pos - len +1;
            }
        } else {
            len = 0;
        }
        pos++;
    }
    return longestPos;
}
console.log(mm('AAGGTGAT', 'AATGTGAT'))
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