Prime

#### Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

#### Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

# TCS DRC Coding Question-1

## Problem Statement –

A marathon is a long-distance race with an official distance of 42.195 kilometers(26 miles 385 yards), usually run as a road race or footrace. A local marathon was organized at Bavdhan, Pune. The distance actually covered by the participants has been recorded in an array R[ ] which is an integer array holding the values in kilometers. If there are N number of participants who started running at a particular time, then the size of R is N. The participants should cover a distance more than 0.0 km to get recorded in array R[ ].

Find the maximum distances covered by the 3 highest racers excluding finishers. If there are only one or two racers excluding finishers, give their distances covered.

R[ ] will be the input float array. Write code to take the Input array R[ ], and return 3 maximum distances excluding Finishing Distance d, d = 42.195 km

Example-1

Input Values

Enter the distances covered by racers in Marathon(Kilometers) please

(press q to terminate):

42.195

42.195

42.195

33.25

40

41.2

38.9

37.5

q

Output Values

Highest Distances excluding Finishers:

[41.2, 40.0, 38.9]

## Solution-

```R = []
print("Enter the distances covered by racers in Marathon(Kilometers) please (press q to terminate):")
num = input()
while num !='q':
R.append(float(num))
num = input()
result = sorted(R)
for i in result:
if i < 0 :
print("Invalid Input")
break
print(result[-4:-7:-1])
```