title: Number Of Pairs In An Array Having Sum Equal To Product
signature: class Solution {
  
      public Integer numberOfPairsInAnArrayHavingSumEqualToProduct(ArrayList<Integer> a, Integer n) {
source_py: def number_of_pairs_in_an_array_having_sum_equal_to_product(a, n):
      zero = 0
      two = 0
      for i in range(n):
          if (a[i] == 0):
              zero += 1
          if (a[i] == 2):
              two += 1
      cnt = (((zero * (zero - 1)) // 2) + ((two * (two - 1)) // 2))
      return cnt
source_cpp: int number_of_pairs_in_an_array_having_sum_equal_to_product(vector<int> a, int n) {
    int zero = 0, two = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( a [ i ] == 0 ) {
        zero ++;
      }
      if ( a [ i ] == 2 ) {
        two ++;
      }
    }
    int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2;
    return cnt;
  }
question_info.extension: java
question_info.entry_fn_name: numberOfPairsInAnArrayHavingSumEqualToProduct
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"a": [9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95], "n": 31}}, {"idx": 1, "outputs": 1, "inputs": {"a": [0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60], "n": 19}}, {"idx": 2, "outputs": 21, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 22}}, {"idx": 3, "outputs": 0, "inputs": {"a": [88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31], "n": 38}}, {"idx": 4, "outputs": 0, "inputs": {"a": [20], "n": 0}}, {"idx": 5, "outputs": 15, "inputs": {"a": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1], "n": 21}}, {"idx": 6, "outputs": 0, "inputs": {"a": [2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89], "n": 24}}, {"idx": 7, "outputs": 0, "inputs": {"a": [-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72], "n": 13}}, {"idx": 8, "outputs": 15, "inputs": {"a": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 15}}, {"idx": 9, "outputs": 0, "inputs": {"a": [22, 15, 28, 29, 32, 16, 33, 83], "n": 7}}]
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> a, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(a, 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(9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95)), 31, 0);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60)), 19, 1);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 22, 21);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31)), 38, 0);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(20)), 0, 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1)), 21, 15);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89)), 24, 0);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72)), 13, 0);
          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, 1)), 15, 15);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(22, 15, 28, 29, 32, 16, 33, 83)), 7, 0);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> a, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(a, 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__