Number of unique triplets

Revision en2, by swordx, 2018-02-26 11:47:35

Hello all,

Could someone share their thoughts on the problem mentioned below:

Given an array of sorted integers, find the number of unique triplets such that (a[i]*a[k])+a[j]=target and i<j<k.

Ex: A={1,3,3,5,5} and target=18 o/p should be {[3,3,5]} . Explanation a[1]*a[3]+a[2].

I know we can solve it in O(n^2) time.

Ques-1: Can we solve it in less than O(n^2) time. If yes, how?

Quest-2: What if the given array is not sorted? What will be the time complexity in this case?

Thanks in advance.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English swordx 2018-02-26 11:47:35 2 Tiny change: 'es, how?\nQuest-2:' -> 'es, how?\n\nQuest-2:'
en1 English swordx 2018-02-26 08:04:47 543 Initial revision (published)