Average Flex Codechef Solution|Problem Code: AVGFLEX

Average Flex Codechef Solution: Hello coders, today we are going to solve Average Flex Codechef Solution.

Codechef solutions

Problem

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

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

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 A1,A2,…,AN – 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≤T≤10001≤T≤1000
  • 1≤N≤1001≤N≤100
  • 0≤Ai≤100

Example

Sample Input 1 


3
3
100 100 100
3
2 1 3
4
30 1 30 30

Sample Output 1 

3
2
3

Average Flex – CodeChef Solution in JAVA

import java.util.Scanner;
public class Main {
  static final int LIMIT = 100;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();
    for (int tc = 0; tc < T; ++tc) {
      int N = sc.nextInt();
      int[] A = new int[N];
      for (int i = 0; i < A.length; ++i) {
        A[i] = sc.nextInt();
      }
      System.out.println(solve(A));
    }
    sc.close();
  }
  static int solve(int[] A) {
    int[] counts = new int[LIMIT + 1];
    for (int score : A) {
      ++counts[score];
    }
    int result = 0;
    int greaterNum = 0;
    for (int i = counts.length - 1; i >= 0; --i) {
      if (A.length - greaterNum > greaterNum) {
        result += counts[i];
      }
      greaterNum += counts[i];
    }
    return result;
  }
}

Average Flex – CodeChef Solution in CPP

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while (n--)
    {
        int a;
        cin>>a;
        int arr[a];
        int sum=0;
        for (int i = 0; i < a; i++)
        {
            cin>>arr[i];
        }
        for (int i = 0; i < a; i++)
        {
        int count=0;
           for (int j = 0; j < a; j++)
           {
               if (arr[i]<arr[j])
                   count++;
               }
               if (count<a-count)
                sum++;
   }
        cout<<sum<<endl;
    }
    return 0;
}

Average Flex – CodeChef Solution in Python

t = int(input())
for i in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    c = 0
    for j in l:
        s = 0
        k = 0
        for z in l:
            if z <= j:
                s += 1
            elif z > j:
                k += 1
        if s > k:
            c += 1
    print(c)

Disclaimer: The above Problem (Average Flex ) is generated by CodeChef but the solution is provided  Chase2learn.This tutorial is only for Educational and Learning purpose.

Leave a Comment