Most Favorite Place in India - TCS NQT

Most Favorite Place in India - TCS NQT 

Problem:

A travel agency is conducting a survey for the most favorite place to visit in India. There are 5 options given to their customers which are given below. 

1 Jaipur 

2 Agra 

3 Rishikesh 

4 Goa 

5 Mysore 

The program must accept a list of integers representing the options selected by the customers. The program must print the name of the most preferred favorite place to visit among the given 5 places as the output. In case of more than one preferred destinations, the program must print the name of those places in the above mentioned order. 

Boundary Condition(s): 

1 <= options <= 5 

Input Format: 

The lines, each containing an integer representing the option selected by a customer. 

Output Format: 

The line(s) containing a string value representing the most preferred favorite place to visit. 

Example Input/Output 1: 

Input: 

Output: 

Agra 

Explanation: 

For each place, the name of the place and the number of customers preferred are given below. Jaipur - 3 Agra - 5 Rishikesh - 2 Goa - 1 Mysore - 2 Here the most preferred favorite place to visit among the given 5 places is Agra. Hence the output is Agra. 

Example Input/Output 2: 

Input: 

Output: 

Rishikesh 

Goa

Program:

city = ['Jaipur','Agra','Rishikesh','Goa','Mysore'] 

l = []

count = [0]*5 

while 1:

    try: 

        x = int(input())

        l.append(x)

        count[x-1] += 1 

    except:

        break

for i in range(1,6):

    if l.count(i) == max(count):

        print(city[i-1])

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number