Click4Ai

4.

Easy

Write a function count_value(arr, value) that counts how many times a specific value appears in an array without using built-in count methods.

Example:

Input: arr = [1, 2, 2, 3, 2, 4, 2], value = 2

Output: 4

Constraints:

  • Array length: 1 <= len(arr) <= 1000
  • Values can be any integer
  • Test Cases

    Test Case 1
    Input: [1, 2, 2, 3, 2, 4, 2], 2
    Expected: 4
    Test Case 2
    Input: [5, 5, 5, 5], 5
    Expected: 4
    Test Case 3
    Input: [1, 2, 3, 4, 5], 6
    Expected: 0
    + 2 hidden test cases