Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Gary and multiplication
EASY
20 mins
13 upvotes
Heap
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Heap
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Gary and multiplication

Contributed by
Ashwani
Easy
yellow-spark
0/40
Avg time to solve 20 mins
Success Rate 85 %
Share
13 upvotes

Problem Statement

Gary has recently learned about priority queues and is quite excited about them. He has asked his teacher for an interesting problem. So, his teacher came up with a simple problem.

The problem is that he now has an integer array 'ARR'. For every index i, he wants to find the product of the largest, second largest and the third largest integer in the range [0, i] given that array has 0 based indexing.

You have to return the list as required.

Note: Two numbers can be the same value-wise but they should be distinct index-wise.

Example:
If the array is [2, 3, 3, 4], the answer should be:-

-1 
-1
18 (3 * 3 * 2)
36 (4 * 3 * 3) 
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample input 1:
1
4  
2 3 1 4 
Sample output 1:
-1 -1 6 24
Explanation
-1 (no second largest as well as third largest element is present)
-1 (no third largest element is present)
6 (3 * 2 * 1)
24 (4 * 3 * 2)
Sample input 2:
1
6 
1 5 7 3 9 12
Sample output 2:
1 -1 35 105 315 756
Reset Code
Full screen
Auto
copy-code
Console