Count Occurrences of a Target - II

You are given an integer array nums and an integer target. Using recursion, return the number of times target occurs in nums.

Note:

A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.

Example 1:

Input: nums = [1, 2, 2, 3, 2], target = 2

Output: 3

Explanation: The target 2 appears three times in nums.

Example 2:

Input: nums = [4, 5, 6, 7], target = 3

Output: 0

Explanation: The target 3 does not occur in nums.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [3, 3, 1, 3, 2, 3], target = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 100
  • -105 <= nums[i] <= 105
  • -105 <= target <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int countOccurrences(vector<int>& nums, int target) {
// Your code goes here
}
};
Test Case

Input:

Nums
Target