Ishaan and Sticks
Easy Accuracy: 37.65% Submissions: 381 Points: 2

Ishaan has a craving for sticks. He has N sticks. He observes that some of his sticks are of the same length, and thus he can make squares out of those.
He wants to know how big a square he can make using those sticks as sides. Since the number of sticks is large, he can't do that manually. Can you tell him the maximum area of the biggest square that can be formed?
Also, calculate how many such squares can be made using the sticks.


Example 1:

​Input : arr[ ] = {2, 2, 2, 9, 2, 2, 2, 2, 2}
Output : 4 2
2 squares of side 2 are formed.
return maximum area and number of square.

​Example 2:

Input : arr[ ] = {5, 3, 2, 3, 6, 3, 3} 
Output :  9 1


Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function square() that takes an array (arr), sizeOfArray (n) and return the array of the maximum area of the largest square that can be formed and the number of squares that can be formed if there is no possible square return -1. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(M), where M is the maximum value of an array.


Constraints : 
1 ≤ N ≤ 105
1 ≤ arri ≤ 103

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?


All Submissions

My Submissions:

Login to access your submissions.

Ishaan and Sticks

Output Window