title: Count Number Of Occurrences Or Frequency In A Sorted Array
signature: function count_number_of_occurrences_or_frequency_in_a_sorted_array(arr, n, x)
source_py: def count_number_of_occurrences_or_frequency_in_a_sorted_array(arr, n, x):
      res = 0
      for i in range(n):
          if (x == arr[i]):
              res += 1
      return res
source_cpp: int count_number_of_occurrences_or_frequency_in_a_sorted_array(vector<int> arr, int n, int x) {
    int res = 0;
    for ( int i = 0;
    i < n;
    i ++ ) if ( x == arr [ i ] ) res ++;
    return res;
  }
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, x, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n, x) 
      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({16, 18, 24, 27, 34, 36, 41, 43, 43, 52, 59, 76, 86, 87, 90, 91, 94, 96, 98, 98}, 14, 43, 2)
      print(string.format("TEST-0...%s",result))
  
      result = driver({64, 66, -36}, 1, 64, 1)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0}, 2, 0, 2)
      print(string.format("TEST-2...%s",result))
  
      result = driver({9, 85, 34, 43, 70, 96, 44, 7, 27, 33, 34, 5, 91, 84, 76, 45, 20, 37, 15, 37, 20, 24, 13, 49, 74, 13, 50, 81, 81, 66, 23, 36, 91, 80, 61, 15, 96, 70, 90, 25, 16, 62, 75, 63, 6, 65, 38, 12}, 43, 5, 1)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -98, -98, -34, -32, -26, -12, 0, 18, 52, 68, 72}, 11, -98, 3)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1}, 11, 1, 5)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 3, 6, 6, 10, 12, 15, 16, 21, 22, 23, 29, 33, 37, 40, 40, 43, 52, 55, 59, 64, 65, 71, 72, 80, 83, 86, 86, 88, 88}, 29, 40, 2)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-14, -30, -38, -38, -8, 40, -34, 2, -84, 68, -42, 38, -14, 0, -64, 12, -2, -38, -8, -44, -88, -34, -80, -36, 82, 70, 96, -32, 16, -52, -12, -46, -28, -86, 30, -14, 50, -44, 22, 30, -4, 78, 52}, 39, 26, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver({1, 1, 1, 1}, 2, 3, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({11, 50, 1, 93, 12, 7, 55, 35, 36, 62, 61, 71, 16}, 11, 8, 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 2, "inputs": {"arr": [16, 18, 24, 27, 34, 36, 41, 43, 43, 52, 59, 76, 86, 87, 90, 91, 94, 96, 98, 98], "n": 14, "x": 43}}, {"idx": 1, "outputs": 1, "inputs": {"arr": [64, 66, -36], "n": 1, "x": 64}}, {"idx": 2, "outputs": 2, "inputs": {"arr": [0, 0, 0], "n": 2, "x": 0}}, {"idx": 3, "outputs": 1, "inputs": {"arr": [9, 85, 34, 43, 70, 96, 44, 7, 27, 33, 34, 5, 91, 84, 76, 45, 20, 37, 15, 37, 20, 24, 13, 49, 74, 13, 50, 81, 81, 66, 23, 36, 91, 80, 61, 15, 96, 70, 90, 25, 16, 62, 75, 63, 6, 65, 38, 12], "n": 43, "x": 5}}, {"idx": 4, "outputs": 3, "inputs": {"arr": [-98, -98, -98, -34, -32, -26, -12, 0, 18, 52, 68, 72], "n": 11, "x": -98}}, {"idx": 5, "outputs": 5, "inputs": {"arr": [1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1], "n": 11, "x": 1}}, {"idx": 6, "outputs": 2, "inputs": {"arr": [1, 3, 6, 6, 10, 12, 15, 16, 21, 22, 23, 29, 33, 37, 40, 40, 43, 52, 55, 59, 64, 65, 71, 72, 80, 83, 86, 86, 88, 88], "n": 29, "x": 40}}, {"idx": 7, "outputs": 0, "inputs": {"arr": [-14, -30, -38, -38, -8, 40, -34, 2, -84, 68, -42, 38, -14, 0, -64, 12, -2, -38, -8, -44, -88, -34, -80, -36, 82, 70, 96, -32, 16, -52, -12, -46, -28, -86, 30, -14, 50, -44, 22, 30, -4, 78, 52], "n": 39, "x": 26}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [1, 1, 1, 1], "n": 2, "x": 3}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [11, 50, 1, 93, 12, 7, 55, 35, 36, 62, 61, 71, 16], "n": 11, "x": 8}}]
question_info.extension: lua
question_info.entry_fn_name: count_number_of_occurrences_or_frequency_in_a_sorted_array
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__