Number of unique triplets

Правка en1, от swordx, 2018-02-26 08:04:47

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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский swordx 2018-02-26 11:47:35 2 Tiny change: 'es, how?\nQuest-2:' -> 'es, how?\n\nQuest-2:'
en1 Английский swordx 2018-02-26 08:04:47 543 Initial revision (published)