Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

GeeksforGeeks-Style Array Counting

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is GeeksforGeeks-Style Array Counting. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Safe Security analyzes arrays of security findings collected from an organization's environment. Given an array of finding identifiers and a target identifier, return the number of times the target appears in the array.

Implement a function that counts exact matches. The array may contain duplicate identifiers, negative integers, and zero. Do not modify the input array.

Formal Specification

  • Input: An integer array findings and an integer target.
  • Output: An integer representing the number of elements in findings equal to target.
  • Matching must use exact integer equality.

Constraints

  • 0 <= findings.length <= 10^5
  • -10^9 <= findings[i] <= 10^9
  • -10^9 <= target <= 10^9
  • The input array must not be modified

Function Signature

def count_occurrences(findings, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output