title: Count Pairs Difference Equal K
signature: class Solution {
  
      public int CountPairsDifferenceEqualK(List<int> arr, int n, int k) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int k, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n, k); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{9, 14, 17, 19, 22, 23, 23, 27, 30, 31, 34, 37, 37, 39, 39, 42, 57, 61, 68, 73, 77, 79, 91, 96, 97}, 19, 19, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-78, -42, 28, -88, 18, -52}, 3, 4, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 16, 14, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{8, 46, 57, 28, 80, 2, 75, 57, 83, 45, 32, 49, 77, 30, 94, 33, 23, 29, 35, 81, 85}, 15, 11, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-90, -72, -72, -62, -62, -54, -54, -52, -48, -38, -22, -22, -22, -12, -12, -8, -8, -8, -6, -6, -2, 6, 12, 26, 26, 28, 28, 38, 40, 48, 52, 52, 58, 60, 68, 70, 72, 76, 76, 76, 92}, 22, 25, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1}, 45, 39, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{3, 13, 19, 23, 27, 32, 49, 52, 54, 57, 58, 58, 63, 67, 68, 68, 69, 70, 75, 80, 86, 90, 91, 95}, 19, 21, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-56, 40, -66, 42, 8, -40, -8, -42}, 7, 6, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 16, 28, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{99, 12, 90, 10, 86, 86, 81, 19, 1, 1, 98, 82, 34, 39, 34, 1, 54, 47, 39, 82, 21, 50, 82, 41, 98, 47, 88, 46, 72, 28, 28, 29, 60, 87, 92, 53, 93, 29, 74, 75, 11, 32, 48, 47, 85, 16, 20}, 24, 45, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }