Bob's Challenge |Programming_info || python_problem_14

 Stella and friends have set out on a vacation to Manali. They have booked accommodation in a resort and the resort authorities headed by Bob, organize Campfires every night as a part of their daily activities. Stella volunteered herself for an activity called the "Stick Game".


Stella was given a total of N sticks. The length of i-th stick is Ai. Bob insists Stella choose any four sticks and make a rectangle with those sticks as its sides. Bob warns Stella not to break any of the sticks, she has to use sticks as a whole.
 
Also, Bob wants that the rectangle formed should have the maximum possible area among all the rectangles that Stella can make. Stella takes this challenge up and overcomes it. You have to help her know whether it is even possible to create a rectangle. If yes, then tell the maximum possible area of the rectangle.
 
Input Format:
The first line of the input contains a single integer N denoting the number of sticks.
The second line of each test case contains N space-separated integers A1A2, ...,AN denoting the lengths of sticks.

Output Format:
Output a single line containing an integer representing the maximum possible area for rectangle or output -1, if it's impossible to form any rectangle using the available sticks.
Refer sample input and output for formatting specifications.

Sample Input 1:
5
1 2 3 1 2

Sample Output 1:
2

Sample Input 2:
4
1 2 2 3

Sample Output 2:
-1

Solution:
n=int(input())
l=list(map(int,input().split()))
r=[]
for i in l:
    c=l.count(i)
    if c>1:
        c1=c//2
        r.extend([i]*c1)
        while i in l:
            l.remove(i)
r.sort()
if len(r)>=2:
    print(r[-2]*r[-1])
else:
    print("-1")

Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support