title: Count Number Of Occurrences Or Frequency In A Sorted Array
signature: func countNumberOfOccurrencesOrFrequencyInASortedArray(arr []int, n int, x int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, x int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n, x),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{16, 18, 24, 27, 34, 36, 41, 43, 43, 52, 59, 76, 86, 87, 90, 91, 94, 96, 98, 98}, 
  	14, 
  	43, 2)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{64, 66, -36}, 
  	1, 
  	64, 1)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0}, 
  	2, 
  	0, 2)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-98, -98, -98, -34, -32, -26, -12, 0, 18, 52, 68, 72}, 
  	11, 
  	-98, 3)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1}, 
  	11, 
  	1, 5)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{1, 1, 1, 1}, 
  	2, 
  	3, 0)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{11, 50, 1, 93, 12, 7, 55, 35, 36, 62, 61, 71, 16}, 
  	11, 
  	8, 0)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }