Jersey Number - Highest in Team

Jersey Number - Highest in Team 

Problem: 

In a school there are N students standing in a straight line. Their Jersey numbers from left to right are passed as the input. The students are to be divided into teams of size T starting from left. First T students form Team 1, next T students form Team 2 and so on. If N is not divisible by T and say the remainder is R, the R students are distributed among the teams formed so far in a round robin fashion (starting from the first team) until the R students are assigned to one of the teams. Once the teams are formed, the program must print the highest jersey number in each team. 

Input Format: 

The first line contains N. The second line contains the jersey numbers of N students separated by a space. The third line contains T. 

Output Format: 

The highest jersey number in each team separated by a space. 

Boundary Conditions: 

1 <= N <= 9999999 

Example Input/Output 1: 

Input: 

10 

1 5 8 2 4 11 20 6 7 9 

Output: 

8 20 

Example Input/Output 2: 

Input: 

10 

1 5 8 2 4 11 3 6 9 7 

Output: 

9 11

Program:

n = int(input())

l = list(map(int,input().split()))

x = int(input())

if n <= x:

    print(max(l))

    quit()

team = []

while l!=[]:

    team.append(l[:x])

    l = l[x:] 

if len(team[-1]) != x:     

    q = team[-1].copy()

    team = team[:-1]

    c = 0

    while q != []:

        team[c%len(team)].append(q[0]) 

        q = q[1:] 

        c += 1 

for i in team:

    print(max(i),end=" ")

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number