Any faster way to find the number of “lucky triples”?

前端 未结 4 1232
盖世英雄少女心
盖世英雄少女心 2021-01-03 10:28

I am working on a code challenge problem -- \"find lucky triples\". \"Lucky triple\" is defined as \"In a list lst, for any combination of triple like (ls

4条回答
  •  星月不相逢
    2021-01-03 11:11

    A precomputation step to the problem can help reduce time complexity.

    Precomputation Step:

    For every element(i), iterate the array to find which are the elements(j) such that lst[j]%lst[i]==0

    for(i=0;i

    This Precomputation Step will take O(n^2) time.

    In the Ultimate Step, use the details of the Precomputation Step, to help find the triplets..

提交回复
热议问题