Cook it Fast

QUESTION

Ram wants to cook food for his mother as she is returning from her journey.As Ram started cooking he forgot the composition of the spices .The composition is in the form of the array of n numbers.Help ram to find the elements in array which have at-least two greater elements \n\nInput:\nThe first line contains size of the array.\nThe second line contains the elements of the array.\n\nOutput:\nThe output contains the elements to be found.

“TESTCASE_1”: “5\n2 8 7 1 5\n###—###SEPERATOR—###—\n2\n1\n5”, “TESTCASE_2”: “6\n7 -2 3 4 9 -1\n###—###SEPERATOR—###—\n-2\n3\n4\n-1”, “TESTCASE_3”: “5\n7 8 2 66 5\n###—###SEPERATOR—###—\n7\n2\n5”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

import java.util.*;
import java.io.*;
 
public class TestClass
{
     
static void findElements(int arr[], int n)
{
    
    for (int i = 0; i < n; i++)
    {
        int count = 0;
         
        for (int j = 0; j < n; j++)
            if (arr[j] > arr[i])
                count++;
 
        if (count >= 2)
        System.out.println(arr[i]);
    }
}
 
// Driver code
public static void main(String args[])
{
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int arr[]=new int[n];
  for(int i=0;i<n;i++)
    arr[i]=sc.nextInt();
  
    findElements(arr, n);
 
}
}
 
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro