Please tell the most optimized solution of this problem

Given a set as [2,4,6]
below operation is performed
2 * 2 = 4
2 * 4 = 8
2 * 6 = 12
4 * 2 = 8
4 * 4 = 16
4 * 6 = 24
6 * 2 = 12
6 * 4 = 24
6 * 6 = 36
And output should be:
4,8,12,16,24,36.
Is it possible to solve this in O(logN)?

Can’t be done in less than O(n^2)

Actually It was asked to do in O(log N) because constraint is given as N<=10^19

No need to display all these stuffs like 4 x 2 or 2 x 4, just answer need to be displayed.

O(logn)? Well, for starters, you’re printing O(n^2) lines. How can the complexity be less than that?

1 Like

If you print n^2 lines the complixity can’t be less than O(n^2).

No need to display a single answer twice and no need to display all these stuffs like 2 * 4 and 4 * 2 and all.

I have edited the question, it was my mistake that in hurry I wrote the operation as output.

O(logn) is impossible. You have to traverse the array. I cannot think if a solution less than O(n^2)

It’s not possible to solve in O(n^2), because solution is then throwing TLE.

share link of the problem

Can’t share, because it was asked in a test and now the link is no more active.
but now question and output is absolutely correct. Output should be in such a manner that a particular number should be displayed only once. Even if it is computed so many times.

With all due respect! Please post question in well described manner along with constraints and sample input output.
Thank you.

also link

1 Like

I am unable to recall the question as it was, because I encountered this in a test and now the test link is no more active. I wrote everything which I can recall at my best and the constraints were 10 to power something.

A link would be great! :sunglasses:

Can’t share, because it was asked in a test and now the link is no more active.

I Can’t share, because it was asked in a test and now the link is no more active.

10 power something is basically every constraint ever.

1 Like

Take it as N <=10^10. As far as I remember, it was near to this number.