Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!