title: Count Pairs Difference Equal K
signature: count_pairs_difference_equal_k <- function(arr, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(9L, 14L, 17L, 19L, 22L, 23L, 23L, 27L, 30L, 31L, 34L, 37L, 37L, 39L, 39L, 42L, 57L, 61L, 68L, 73L, 77L, 79L, 91L, 96L, 97L), 19L, 19L, 
          3L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-78L, -42L, 28L, -88L, 18L, -52L), 3L, 4L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 16L, 14L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(8L, 46L, 57L, 28L, 80L, 2L, 75L, 57L, 83L, 45L, 32L, 49L, 77L, 30L, 94L, 33L, 23L, 29L, 35L, 81L, 85L), 15L, 11L, 
          3L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-90L, -72L, -72L, -62L, -62L, -54L, -54L, -52L, -48L, -38L, -22L, -22L, -22L, -12L, -12L, -8L, -8L, -8L, -6L, -6L, -2L, 6L, 12L, 26L, 26L, 28L, 28L, 38L, 40L, 48L, 52L, 52L, 58L, 60L, 68L, 70L, 72L, 76L, 76L, 76L, 92L), 22L, 25L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L), 45L, 39L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 13L, 19L, 23L, 27L, 32L, 49L, 52L, 54L, 57L, 58L, 58L, 63L, 67L, 68L, 68L, 69L, 70L, 75L, 80L, 86L, 90L, 91L, 95L), 19L, 21L, 
          2L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-56L, 40L, -66L, 42L, 8L, -40L, -8L, -42L), 7L, 6L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 16L, 28L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(99L, 12L, 90L, 10L, 86L, 86L, 81L, 19L, 1L, 1L, 98L, 82L, 34L, 39L, 34L, 1L, 54L, 47L, 39L, 82L, 21L, 50L, 82L, 41L, 98L, 47L, 88L, 46L, 72L, 28L, 28L, 29L, 60L, 87L, 92L, 53L, 93L, 29L, 74L, 75L, 11L, 32L, 48L, 47L, 85L, 16L, 20L), 24L, 45L, 
          3L
      )))
  
  }
  
  main()
source_py: def count_pairs_difference_equal_k(arr, n, k):
      count = 0
      for i in range(0, n):
          for j in range((i + 1), n):
              if (((arr[i] - arr[j]) == k) or ((arr[j] - arr[i]) == k)):
                  count += 1
      return count
source_cpp: int count_pairs_difference_equal_k(vector<int> arr, int n, int k) {
    int count = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      for ( int j = i + 1;
      j < n;
      j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++;
    }
    return count;
  }