What if the question is to find the number of triplets, instead of index?


  • 1
    P

    I'm wondering what if the problem asks us to find the number of distinct triplets, instead of number of index triplets. Can we still solve it in O(n^2)? What's the good way to do it?


  • 2
    K

    No. In the original problem, we can get the number of solutions from indices directly. But if you want all the combinations of numbers, you need to look back to all the numbers before index start. Hence, it will be O(n^3).


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.