Average Flex Solution in JAVA

Problem

There are N students in a class, where the i-th student has a score of A_i.

The i-th student will boast if and only if the number of students scoring less than or equal A_i is greater than the number of students scoring greater than A_i.

Find the number of students who will boast.

Input Format

  • The first line contains T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains a single integer N - the number of students.
  • The second line of each test case contains N integers A_1, A_2, \dots, A_N - the scores of the students.

Output Format

For each test case, output in a single line the number of students who will boast.

Constraints

  • 1 \leq T \leq 1000
  • 1 \leq N \leq 100
  • 0 \leq A_i \leq 100

Sample 1:

Input
Output
3
3
100 100 100
3
2 1 3
4
30 1 30 30
3
2
3

Explanation:

  • Test case 1: All three students got the highest score. So all three of them will boast.
  • Test case 2: Only the student with score 1 will not be able to boast.
  • Test case 3: Only the student with score 1 will not be able to boast.





Program :


 import java.util.*;

import java.lang.*;

import java.io.*;


/* Name of the class has to be "Main" only if the class is public. */

class Codechef

{

public static void main (String[] args) throws java.lang.Exception

{

Scanner sc = new Scanner(System.in);


int t = sc.nextInt();

while(t-->0)

{

int l = sc.nextInt();

int m[] = new int[l];


for(int i=0; i<m.length; i++)

{

m[i] = sc.nextInt();

}


int count = 0;

for(int i=0; i<l; i++)

{

int lower=0, higher=0;


for(int j=0; j<l; j++)

{

if(m[j] <= m[i])

lower++;

else

higher++;

}


if(lower>higher)

count++;

}

System.out.println(count);

}

}

}

Post a Comment

0 Comments