Aho-Corasick algorithm to scan through a list of strings
This code is slow because:


It builds a new keyword tree for each test case. Just build it once, using all the genes.
It builds a list of all the matching keywords. KeywordTree.search_all() is a generator, just loop over it directly. And,
It loops over the list of genes to find the gene index, so that it can find the health.
Instead, build a dict with the genes as keys and an (index, health) tuple for the value. 


Something like this (untested):

import math
from collections import defaultdict
from ahocorapy.keywordtree import KeywordTree


def geneshealth(genes, health, testcases):

    # build the kwtree using all the genes 
    kwtree = KeywordTree(case_insensitive=True)
    for gene in genes:
        kwtree.add(gene)
    kwtree.finalize()

    # build a dict that maps a gene to a list of (index, health) tuples
    index_and_health = defaultdict(list)
    for gene, data in zip(genes, enumerate(health)):
        index_and_health[gene].append(data)

    min_dna_health = math.inf
    max_dna_health = -math.inf

    for case in testcases:
        start, end, dna = case.split()
        start = int(start)
        end = int(end)

        dna_health = 0

        # search the dna for any genes in the kwtree
        # note: we don't care where the gene is in the dna
        for gene, _ in kwtree.search_all(dna):

            for gene_index, gene_health in index_and_health[gene]:

                # only genes that are within the testcase limits
                # contribute dna_health
                if start &lt;= gene_index &lt;= end:
                    dna_health += gene_health

        # keep the min/max weight
        if dna_health &lt; min_dna_health:
            min_dna_health = dna_health

        if dna_health &gt; max_dna_health:
            max_dna_health = dna_health

    return(min_dna_health, max_dna_health)