Honest coach sloution 2022 |python

 HONEST COACH SOLUTION PYTHON





Q.There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete - the athlete number i has the strength s..
You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team.
You want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. Formally, you want to split the athletes into two teams A and B so that the value max(A) - min(B) is as small as possible, where max(A) is the maximum strength of an athlete from team A, and min(B) is the minimum strength of an athlete from team B.
For example, if n = 5 and the strength of the athletes is s = [3, 1, 2, 6, 4], then one of the possible split into teams is:


⚫ first team: A = [1,2,4],

⚫ second team: B = [3,6].

In this case, the value | max(A) - min (B) will be equal to 4-3)= 1. This example illustrates one of the ways of optimal split into two teams.

Print the minimum value max(A) - min(B).

Input

The first line contains an integer t (1<<1000) - the number of test cases in the input. Then t test cases follow.

Each test case consists of two lines.

The first line contains positive integer n (2≤ n ≤50)-number of athletes.

The second line contains n positive integers 81, 82, that s values may not be distinct.





"""

HONEST COACH SOLUTION IN PYTHON 


TESTCASES1:

    Input 5

      1 2 3 4 5

     Output

        1

TESTCASES2:

    Input 4

    5 2 3 7

    Output

    2 


What is going in program is:

    Taking players as a number

    Now we are spliting or bifarcating the players into two teams

    And finally find the difference of max number of any player of first team and min number assign to the player of another team

    

Let understand team=[1,2,3,4,5]

after splitting the palyers

team1=[1,2,3]

team2=[4,5]

maximum from the team1 is 3

minimum from the team2 is 4

Now difference is -1 but we have to print as positive number

"""



"""
TESTCASES1:

    Input 5

      1 2 3 4 5

     Output

        1

TESTCASES2:

    Input 4

    5 2 3 7

    Output

    2
"""

n=int(input("Enter number of palyers are there:"))

_team=[]

team1=[]

team2=[]

for i in range(0,n):

    a=int(input("Enter player number:"))

    _team.append(a)

print("Strength of the team is",len(_team))

mid=len(_team)//2

for i in range(mid+1):

    team1.append(_team[i])



   

print("Team first is:",team1)



for j in range(mid+1,len(_team)):

    team2.append(_team[j])

   

print("Team second is:",team2)



diff=max(team1)-min(team2)

print(abs(diff))                   #abs()  function is to give positive value






No comments:

Powered by Blogger.