title: Count Pairs Difference Equal K 1
signature: function count_pairs_difference_equal_k_1(arr, n, k)
source_py: def count_pairs_difference_equal_k_1(arr, n, k):
      count = 0
      arr.sort()
      l = 0
      r = 0
      while (r < n):
          if ((arr[r] - arr[l]) == k):
              count += 1
              l += 1
              r += 1
          elif ((arr[r] - arr[l]) > k):
              l += 1
          else:
              r += 1
      return count
source_cpp: int count_pairs_difference_equal_k_1(vector<int> arr, int n, int k) {
    int count = 0;
    sort(arr.begin(), arr.end());
    int l = 0;
    int r = 0;
    while ( r < n ) {
      if ( arr [ r ] - arr [ l ] == k ) {
        count ++;
        l ++;
        r ++;
      }
      else if ( arr [ r ] - arr [ l ] > k ) l ++;
      else r ++;
    }
    return count;
  }
question_info.entry_fn_name: count_pairs_difference_equal_k_1
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n, k) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({5, 5, 10, 19, 29, 32, 40, 60, 65, 70, 72, 89, 92}, 7, 12, 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-98, -90, -88, -82, -80, -78, -74, -74, -72, -62, -58, -58, -56, -52, -48, -46, -38, -38, -30, -12, -10, 4, 8, 8, 14, 22, 24, 26, 36, 40, 40, 48, 56, 58, 58, 58, 60, 62, 64, 68, 68, 74, 84}, 24, 36, 7)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 1}, 1, 1, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver({1, 7, 13, 14, 16, 29, 34, 42, 44, 49, 59, 62, 65, 66, 70, 71, 73, 73, 76, 80, 96, 96}, 12, 16, 1)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -88, -58, -56, -48, -34, -22, -18, -14, -14, -8, -4, -2, 2, 18, 38, 42, 46, 54, 68, 70, 90, 94, 96, 98}, 23, 22, 4)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 1, 1}, 2, 1, 1)
      print(string.format("TEST-5...%s",result))
  
      result = driver({11, 43, 50, 58, 60, 68, 75}, 4, 4, 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-80, -56, -10, 0, 6, 8, 24, 42, 52, 86, 88, 94}, 11, 9, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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, 1, 1, 1}, 29, 30, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({4, 7, 9, 9, 14, 34, 34, 36, 50, 54, 80, 81, 99}, 9, 8, 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [5, 5, 10, 19, 29, 32, 40, 60, 65, 70, 72, 89, 92], "n": 7, "k": 12}}, {"idx": 1, "outputs": 7, "inputs": {"arr": [-98, -90, -88, -82, -80, -78, -74, -74, -72, -62, -58, -58, -56, -52, -48, -46, -38, -38, -30, -12, -10, 4, 8, 8, 14, 22, 24, 26, 36, 40, 40, 48, 56, 58, 58, 58, 60, 62, 64, 68, 68, 74, 84], "n": 24, "k": 36}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0, 1], "n": 1, "k": 1}}, {"idx": 3, "outputs": 1, "inputs": {"arr": [1, 7, 13, 14, 16, 29, 34, 42, 44, 49, 59, 62, 65, 66, 70, 71, 73, 73, 76, 80, 96, 96], "n": 12, "k": 16}}, {"idx": 4, "outputs": 4, "inputs": {"arr": [-98, -88, -58, -56, -48, -34, -22, -18, -14, -14, -8, -4, -2, 2, 18, 38, 42, 46, 54, 68, 70, 90, 94, 96, 98], "n": 23, "k": 22}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [0, 1, 1], "n": 2, "k": 1}}, {"idx": 6, "outputs": 0, "inputs": {"arr": [11, 43, 50, 58, 60, 68, 75], "n": 4, "k": 4}}, {"idx": 7, "outputs": 0, "inputs": {"arr": [-80, -56, -10, 0, 6, 8, 24, 42, 52, 86, 88, 94], "n": 11, "k": 9}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [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, 1, 1, 1], "n": 29, "k": 30}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [4, 7, 9, 9, 14, 34, 34, 36, 50, 54, 80, 81, 99], "n": 9, "k": 8}}]