Techgig code gladiators 2020 solutions  Python Practice
TestII Solution
Problem Statements
Beyblade World Championship
Tyson is all prepared for the Beyblade World Championship. The tournament is teambased and each team can have N members. A player can fight against a singleplayer only. Team GRevolution is all excited and pumped up as they have practiced a lot. Kenny, the mind of team GRevolution, has created a database where he has the data about the power of other teams members and his own team members. The tournament is going to start in some time and Kenny moves to the cafeteria to have a snack before the competition.
The team GRevolution is to fight in some time and they are tensed up as someone has kidnapped Kenny from the cafeteria. They have made a police complaint and the police are searching for Kenny. Luckily, they have found his device with all the data. The problem is, the data is present randomly and not in the order they have to fight the opponent. Team GRevolution wants to win at any cost and for that, they need the order in which they have to fight optimally to win the maximum number of battles.
A player can win only when his/her Beyblade power is strictly greater than the opponent's Beyblade power.
Example:
Consider the team size is 3, N = 3
The 3 players of both the teams are shown with their Beyblade powers.
Team, All Starz is presented in the order: Michael, Eddy, Steve
With the given arrangement, Team GRevolution would be able to win only 1 fight. Team GRevolution should be shuffled in an optimal manner as below:
The maximum number of fights Team GRevolution can win is 2 when they are arranged optimally or fight in an optimal order.
Team GRevolution needs help with the device. Tyson has heard about your skills and called you up to help them shuffle their positions in an order such that they would be able to win the maximum number of fights. Can you help Tyson and Team GRevolution?
How to solve this problem
Explanation of the problem statements
Input Format
The first line of input consists of the number of test cases, T
The first line of each test case consists of the number of members each team can have, N.
The second line of each test case consists of N spaceseparated integers representing the power of Beyblades of Team GRevolution members.
The third line of each test case consists of N spaceseparated integers representing the power of Beyblades of opponent team members.
Constraints
1<= T <=100000
1<= N <=100000
0<= Power of Beyblade <= LLONG_MAX
Output Format
For each test case, print the maximum number of fights Team GRevolution can win if they go to fight in an optimal manner.How to solve this problem:
So, first, we make a line of code to take input from the user (Such as the number of the test case).
Now, make a variable named count and set as 0.
Then, we will make a result list that stores the result of the input.
Then we will iterate the while loop for checking the number of the test cases.
Then again, we will take the input of the number of players from the user.
Now the next step is to split the input.
Now we will reverse the input of a number of players and villian.
So, first, we make a line of code to take input from the user (Such as the number of the test case).
Now, make a variable named count and set as 0.
Then, we will make a result list that stores the result of the input.
Then we will iterate the while loop for checking the number of the test cases.
Then again, we will take the input of the number of players from the user.
Now the next step is to split the input.
Now we will reverse the input of a number of players and villian.
Solution:
In Python3 and JAVA8
In python3:
def main():
a=int(input())
while a>0:
count=0
n=int(input())
g=list(map(int,input().split()))
x=list(map(int,input().split()))
g.sort(reverse=True)
x.sort(reverse=True)
p=0
for i in range(n):
for j in range(p,n):
if g[i]>x[j]:
p=j+1
count+=1
break
print(count)
a=1
main()
# Made by Ankur Patel
In JAVA8
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(reader.readLine());
while (cases > 0) {
int count = 0;
int numberOfMember = Integer.parseInt(reader.readLine()); // 5
String[] firstTeam = reader.readLine().split(" ");
String[] secondTeam = reader.readLine().split(" ");
Integer[] firstTeamInt = Stream.of(firstTeam).mapToInt(Integer::parseInt).boxed().toArray(Integer[]::new);
Integer[] secondTeamInt = Stream.of(secondTeam).mapToInt(Integer::parseInt).boxed().toArray(Integer[]::new);
Arrays.sort(firstTeamInt, Collections.reverseOrder());
Arrays.sort(secondTeamInt, Collections.reverseOrder());
int point = 0;
for (int i = 0; i < numberOfMember; i++) {
for (int j = point; j < numberOfMember; j++) { // 0 1 4
if (firstTeamInt[i] > secondTeamInt[j]) {
point = j + 1;
count++;
break;
}
}
}
System.out.println(count);
cases;
}
// Made by Ankur Patel
def main(): a=int(input()) while a>0: count=0 n=int(input()) g=list(map(int,input().split())) x=list(map(int,input().split())) g.sort(reverse=True) x.sort(reverse=True) p=0 for i in range(n): for j in range(p,n): if g[i]>x[j]: p=j+1 count+=1 break print(count) a=1 main() # Made by Ankur Patel 
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(reader.readLine()); while (cases > 0) { int count = 0; int numberOfMember = Integer.parseInt(reader.readLine()); // 5 String[] firstTeam = reader.readLine().split(" "); String[] secondTeam = reader.readLine().split(" "); Integer[] firstTeamInt = Stream.of(firstTeam).mapToInt(Integer::parseInt).boxed().toArray(Integer[]::new); Integer[] secondTeamInt = Stream.of(secondTeam).mapToInt(Integer::parseInt).boxed().toArray(Integer[]::new); Arrays.sort(firstTeamInt, Collections.reverseOrder()); Arrays.sort(secondTeamInt, Collections.reverseOrder()); int point = 0; for (int i = 0; i < numberOfMember; i++) { for (int j = point; j < numberOfMember; j++) { // 0 1 4 if (firstTeamInt[i] > secondTeamInt[j]) { point = j + 1; count++; break; } } } System.out.println(count); cases; } // Made by Ankur Patel 

Hi Ankur,
I also wrote python script with same logic but i did sort not reverse sort. My testcase got passed only for sample. Other testcases are failed. I dont know why it is failed. Because your script and my script both are same. Can you please tell how you passed this python script and do you also faced sample alone passed ever in your try.
Thanks
Farveen
I think in your script first while loop is missing. The first while loop is for the number of the test case. That's why your script is failed in the other test cases.Please check it and reply me.And if your script alread have a while loop then please share your code in comment or Email.
By
Ankur Patel