title: Count Subarrays Total Distinct Elements Original Array
signature: function count_subarrays_total_distinct_elements_original_array(arr, n)
source_py: def count_subarrays_total_distinct_elements_original_array(arr, n):
      vis = dict()
      for i in range(n):
          vis[arr[i]] = 1
      k = len(vis)
      vid = dict()
      ans = 0
      right = 0
      window = 0
      for left in range(n):
          while ((right < n) and (window < k)):
              if (arr[right] in vid.keys()):
                  vid[arr[right]] += 1
              else:
                  vid[arr[right]] = 1
              if (vid[arr[right]] == 1):
                  window += 1
              right += 1
          if (window == k):
              ans += ((n - right) + 1)
          vid[arr[left]] -= 1
          if (vid[arr[left]] == 0):
              window -= 1
      return ans
source_cpp: int count_subarrays_total_distinct_elements_original_array(vector<int> arr, int n) {
    unordered_map < int, int > vis;
    for ( int i = 0;
    i < n;
    ++ i ) vis [ arr [ i ] ] = 1;
    int k = vis . size ( );
    vis . clear ( );
    int ans = 0, right = 0, window = 0;
    for ( int left = 0;
    left < n;
    ++ left ) {
      while ( right < n && window < k ) {
        ++ vis [ arr [ right ] ];
        if ( vis [ arr [ right ] ] == 1 ) ++ window;
        ++ right;
      }
      if ( window == k ) ans += ( n - right + 1 );
      -- vis [ arr [ left ] ];
      if ( vis [ arr [ left ] ] == 0 ) -- window;
    }
    return ans;
  }
question_info.entry_fn_name: count_subarrays_total_distinct_elements_original_array
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, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      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({13, 39, 49, 52, 53, 69, 72, 79, 83, 96}, 5, 1)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-98, -98, 22, -10, -28, 0, 56, 72, 36, 88, 96, 22, 90, 74, -60, -64, 0, 2, -42, 0, 94, -82, -74}, 20, 4)
      print(string.format("TEST-1...%s",result))
  
      result = driver({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}, 26, 160)
      print(string.format("TEST-2...%s",result))
  
      result = driver({35, 23, 41, 58, 66, 92, 3, 33, 78, 70, 80, 86, 21, 21, 74, 19}, 12, 1)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -80, -52, -10, 4, 76}, 3, 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1}, 36, 609)
      print(string.format("TEST-5...%s",result))
  
      result = driver({2, 7, 10, 17, 26, 36, 37, 85, 87, 88}, 8, 1)
      print(string.format("TEST-6...%s",result))
  
      result = driver({64, -2, -94, -84, -48, 86}, 5, 1)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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, 1, 1, 1, 1}, 20, 91)
      print(string.format("TEST-8...%s",result))
  
      result = driver({91, 49, 94, 81, 64, 5, 13, 70, 82, 9, 80, 82}, 9, 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"arr": [13, 39, 49, 52, 53, 69, 72, 79, 83, 96], "n": 5}}, {"idx": 1, "outputs": 4, "inputs": {"arr": [-98, -98, 22, -10, -28, 0, 56, 72, 36, 88, 96, 22, 90, 74, -60, -64, 0, 2, -42, 0, 94, -82, -74], "n": 20}}, {"idx": 2, "outputs": 160, "inputs": {"arr": [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], "n": 26}}, {"idx": 3, "outputs": 1, "inputs": {"arr": [35, 23, 41, 58, 66, 92, 3, 33, 78, 70, 80, 86, 21, 21, 74, 19], "n": 12}}, {"idx": 4, "outputs": 1, "inputs": {"arr": [-98, -80, -52, -10, 4, 76], "n": 3}}, {"idx": 5, "outputs": 609, "inputs": {"arr": [1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1], "n": 36}}, {"idx": 6, "outputs": 1, "inputs": {"arr": [2, 7, 10, 17, 26, 36, 37, 85, 87, 88], "n": 8}}, {"idx": 7, "outputs": 1, "inputs": {"arr": [64, -2, -94, -84, -48, 86], "n": 5}}, {"idx": 8, "outputs": 91, "inputs": {"arr": [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, 1, 1, 1, 1], "n": 20}}, {"idx": 9, "outputs": 1, "inputs": {"arr": [91, 49, 94, 81, 64, 5, 13, 70, 82, 9, 80, 82], "n": 9}}]