title: Count Inversions Of Size Three In A Give Array 1
signature: class Solution {
  
      public Integer countInversionsOfSizeThreeInAGiveArray1(ArrayList<Integer> arr, Integer n) {
source_py: def count_inversions_of_size_three_in_a_give_array_1(arr, n):
      invcount = 0
      for i in range(1, (n - 1)):
          small = 0
          for j in range((i + 1), n):
              if (arr[i] > arr[j]):
                  small += 1
          great = 0
          for j in range((i - 1), (- 1), (- 1)):
              if (arr[i] < arr[j]):
                  great += 1
          invcount += (great * small)
      return invcount
source_cpp: int count_inversions_of_size_three_in_a_give_array_1(vector<int> arr, int n) {
    int invcount = 0;
    for ( int i = 1;
    i < n - 1;
    i ++ ) {
      int small = 0;
      for ( int j = i + 1;
      j < n;
      j ++ ) if ( arr [ i ] > arr [ j ] ) small ++;
      int great = 0;
      for ( int j = i - 1;
      j >= 0;
      j -- ) if ( arr [ i ] < arr [ j ] ) great ++;
      invcount += great * small;
    }
    return invcount;
  }
question_info.extension: java
question_info.entry_fn_name: countInversionsOfSizeThreeInAGiveArray1
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [4, 75, 89], "n": 1}}, {"idx": 1, "outputs": 404, "inputs": {"arr": [84, -66, -52, 34, -28, -6, 20, 22, -78, -26, 14, 24, -92, -18, 32, -94, -64, -38, 56, 4, -10, 58, -66, -58, -10, -8, -62, -60, -26], "n": 26}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0, 0, 1, 1, 1, 1, 1], "n": 7}}, {"idx": 3, "outputs": 37, "inputs": {"arr": [18, 7, 43, 57, 94, 37, 38, 41, 59, 64, 97, 29, 51, 37, 64, 91, 42, 83, 13, 22, 68], "n": 17}}, {"idx": 4, "outputs": 0, "inputs": {"arr": [-94, -86, -84, -84, -82, -66, -62, -58, -52, -48, -44, -40, -38, -32, -22, -22, -22, -14, -8, -6, -6, 0, 2, 20, 20, 26, 32, 32, 52, 56, 66, 74, 76, 80, 80, 86, 88, 94], "n": 34}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0], "n": 9}}, {"idx": 6, "outputs": 0, "inputs": {"arr": [4, 8, 15, 19, 24, 31, 33, 36, 38, 45, 45, 52, 54, 65, 73, 75, 83, 84, 90, 92, 93], "n": 19}}, {"idx": 7, "outputs": 20, "inputs": {"arr": [80, -30, -44, 76, -96, 2, 22, -30, 36, -6, 88, -60, -90, -52, 78, 90, -52], "n": 10}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 7}}, {"idx": 9, "outputs": 43, "inputs": {"arr": [74, 71, 28, 45, 14, 31, 17, 10, 82, 27, 45, 73, 93, 87, 57, 58], "n": 10}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(4, 75, 89)), 1, 0);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(84, -66, -52, 34, -28, -6, 20, 22, -78, -26, 14, 24, -92, -18, 32, -94, -64, -38, 56, 4, -10, 58, -66, -58, -10, -8, -62, -60, -26)), 26, 404);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 1, 1, 1, 1, 1)), 7, 0);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(18, 7, 43, 57, 94, 37, 38, 41, 59, 64, 97, 29, 51, 37, 64, 91, 42, 83, 13, 22, 68)), 17, 37);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-94, -86, -84, -84, -82, -66, -62, -58, -52, -48, -44, -40, -38, -32, -22, -22, -22, -14, -8, -6, -6, 0, 2, 20, 20, 26, 32, 32, 52, 56, 66, 74, 76, 80, 80, 86, 88, 94)), 34, 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0)), 9, 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(4, 8, 15, 19, 24, 31, 33, 36, 38, 45, 45, 52, 54, 65, 73, 75, 83, 84, 90, 92, 93)), 19, 0);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(80, -30, -44, 76, -96, 2, 22, -30, 36, -6, 88, -60, -90, -52, 78, 90, -52)), 10, 20);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 7, 0);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(74, 71, 28, 45, 14, 31, 17, 10, 82, 27, 45, 73, 93, 87, 57, 58)), 10, 43);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__