Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5765 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4993 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1282 |

@bt8816103042 | 739 |

@rohitanand | 495 |

@codeantik | 479 |

@shalinibhataniya1097 | 472 |

@amrutakashikar2 | 464 |

@thealchemist627 | 456 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@dalwainazism125 | 453 |

@SherlockHolmes3 | 447 |

Complete Leaderboard |

Given an array **A** of **N** elements. The task is to find the greatest number **S** such that it is product of two elements of given array (S cannot be included in pair. Also, pair must be from different indices).

**Example 1:**

**Input :** arr[] = {10, 3, 5, 30, 35}
**Output:** 30
**Explanation:** 30 is the product of 10 and 3.

**Input :** arr[] = {2, 5, 7, 8}
**Output:** -1
**Explanation:** Since, no such element exists.

**Input :** arr[] = {10, 2, 4, 30, 35}
**Output:** -1

**Input :** arr[] = {10, 2, 2, 4, 30, 35}
**Output:** 4

**Input :** arr[] = {17, 2, 1, 35, 30}
**Output :** 35

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **findGreatest()** which takes the array **arr[]** and its size **N **as inputs and returns the answer. If the answer is not present in the array, return **-1**.

**Expected Time Complexity:** O(N. Log(N))

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N ≤ 10^{6}

1 ≤ A_{i} ≤ 10^{7}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Pair with greatest product in array

...