SHARE
TWEET

Untitled

a guest Jan 24th, 2020 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2.  
  3. public class Mahendra {
  4.  
  5.     public static void mostCommonVal(int[][] elevations) {
  6.         int[] ar=new int[elevations.length*elevations[0].length];
  7.         for(int i=0;i<elevations.length;i++)
  8.             for(int j=0;j<elevations[0].length;j++)
  9.                 ar[i*elevations[0].length+j]=elevations[i][j];
  10.  
  11.         Arrays.sort(ar);
  12.  
  13.         int[] arr=new int[ar.length];
  14.         arr[0]=1;
  15.         for(int i=1;1<ar.length;i++) {
  16.             if(ar[i]==ar[i-1])
  17.                 arr[i]=arr[i]+1;
  18.             else
  19.                 arr[i]=1;
  20.         }
  21.  
  22.         int max=Integer.MIN_VALUE;
  23.         int maxIndex=-1;
  24.  
  25.         for(int i=0;i<arr.length;i++){
  26.             if(max<arr[i]){
  27.                 maxIndex=i;
  28.                 max=arr[i];
  29.             }
  30.         }
  31.  
  32.         System.out.println(ar[maxIndex]);
  33.  
  34.  
  35.  
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top