Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6564 |

@blackshadows | 6400 |

@mb1973 | 5785 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4639 |

@sanjay05 | 3762 |

@mantu_singh | 3712 |

@gfgaccount | 3627 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@yaswanthero123 | 625 |

@vikash619 | 611 |

@venkat11803610 | 501 |

@roshan13ar | 396 |

@DevangSingh | 379 |

@ravi11815721 | 312 |

@hrishipangavhane | 286 |

@aryanjain85297 | 280 |

@kommaraju11806903 | 277 |

@infosumitraut | 272 |

@ankitsharma5422 | 256 |

Complete Leaderboard |

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
**Explanation:**
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 ≤ 10^{5}

1 ≤ arr_{i} ≤ 10^{3}

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?

YesLoading...

Ishaan and Sticks

...