1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Problem #2094 Leetcode - Code does not return O(3) instead of O(n)

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    Ok, currently the code runs but when submitted it shows me this error on the terminal:

    Wrong Answer
    3 / 79 testcases passed

    Editorial
    Input
    digits = [2,1,3,0]

    Use Testcase
    Output
    [102,300,302,400,402,500]
    Expected
    [102,120,130,132,210,230,302,310,312,320]


    From what I understood last time, when I initially solved it, my code was adding different variables (previously) in O(n), and I understood that it's very slow when the numbers are very large. So, according to Deepseek's recommendations, the best thing to do would be to "count the repetitions" and "avoid correcting a number to a list once." However, I'm still getting that error in the terminal.

    I tried importing Counter and also created a single variable Counter(digits) where I would put all the digits or well it's like a dictionary and I added this code where I had the logic before to reduce the time when counting the list repeatedly:

    conteo = Counter([primer_digito, segundo_digito, tercer_digito])
    valido = all(conteo[d] <= digit_count[d] for d in conteo)


    this is my code:

    from collections import Counter
    def findEvenNumbers(digits):
    result = []
    digit_count = Counter(digits)

    for primer_digito in digits:
    if primer_digito == 0:
    continue
    for segundo_digito in digits:
    for tercer_digito in digits:
    if tercer_digito % 2 != 0:
    continue

    conteo = Counter([primer_digito, segundo_digito, tercer_digito])
    valido = all(conteo[d] <= digit_count[d] for d in conteo)

    if valido:
    numero = primer_digito*100 +segundo_digito*100 +tercer_digito
    result.append(numero)

    result = sorted(set(result))
    return result


    digits = [2, 1, 3, 0]
    print(findEvenNumbers(digits))

    digits = [2, 1, 3, 0]
    print(findEvenNumbers(digits))


    I know that several have already done this leetcode problem but I want to know where my error could be so that it shows me that error when I submit the problem, here I leave my complete code for you to review and tell me your recommendations ;)

    Link of the problem for context: problem2092

    Continue reading...

Compartilhe esta Página