• + 0 comments

    JAVA

    class Result {

    /*
     * Complete the 'cutTheSticks' function below.
     *
     * The function is expected to return an INTEGER_ARRAY.
     * The function accepts INTEGER_ARRAY arr as parameter.
     */
    
    public static List<Integer> cutTheSticks(List<Integer> arr) {
    // Write your code here
      int temp1 = 0 ;
      int n = Collections.max(arr) ; 
      int [] temp = new int [n+1] ;
      List<Integer> ans = new ArrayList<>(); 
         ans.add(arr.size() - temp1 ) ; 
      for (int i =0 ; i < arr.size() ; i++) {
          temp [arr.get(i)] ++ ;
      } 
    
       for (int i =0 ; i < temp.length ; i++) { 
    
           if (temp[i] > 0) {
           temp1+= temp[i]; 
           if (temp1 == arr.size() ) {
               return ans ;
           }
           ans.add(arr.size() - temp1 ) ; 
           } 
      }
      return ans;
    }
    

    }