Wednesday, 8 December 2021

Best Couple Event Problem !!!

 PROBLEM 33: Best Couple Event 


"Shades" Television Channel organizes a fun-filled event named "Best Couple 2021" where in married couples would be invited and given many tasks and activities. Based on some criteria decided by the jury, a best couple will be chosen.

"N" couples registered for the event and each couple was given a unique registration number. One specific couple's registration ID got missed. The event coordinators wanted your help in finding the missing ID. 

Write a program which takes an array of registration numbers as input and outputs the missing registration ID. 


Input: 

First line of the input contains the number of couples N who registration for the event. Assume that the maximum value of the N can be 50. 

Second line of input contains N registration ID of each of the couple separated by a space. 


Output:

Output in a single line the missing registration ID.


Solution:


import sys

n = int(input())

a = []

for i in range(0,n):

    b = int(input())

    a.append(b)


a.sort()

i = 0 

while i < n:

    if i+1 >= n:

        print(a[n-1])

        sys.exit()

        

    if a[i] == a[i+1]:

        i = i + 2

    else:

        break

print(a[i])



The above solution is in python language. 


Example:

Input :

3

1 2 1

Output: 

2


Input:

5

1 1 2 2 3

Output: 

3


Input:

5

1 2 2 3 3

Output:

1


Input:

5

1 1 2 3 3

Output:

2



No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...