Batch Quality Control

Easy
0/40
profile
Contributed by
1 upvote
Asked in company
Freecharge

Problem statement

You are working at a factory that produces electronic components. Each component is assigned a unique serial number. As part of a new quality control initiative, a component is flagged for inspection if its serial number is evenly divisible by a specific integer K.


You are given a batch of N components, represented by an array A of their serial numbers, and a single integer K. Your task is to count how many components in this batch need to be flagged for inspection.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains two space-separated integers, N (the number of components) and K (the divisor).

The second line contains N space-separated integers, the elements of the array A (the serial numbers).


Output Format:
The output should be a single integer representing the total count of elements in A that are evenly divisible by K.


Note:
An integer a is evenly divisible by an integer b if the remainder of their division is 0. In most programming languages, this is checked with the modulo operator: a % b == 0.

The value of K will always be a positive integer.
Sample Input 1:
5 3
1 2 3 4 6


Sample Output 1:
2


Explanation for Sample 1:
We need to check which of the numbers [1, 2, 3, 4, 6] are divisible by 3.
 - 1 % 3 != 0
 - 2 % 3 != 0
 - 3 % 3 == 0 (Count: 1)
 - 4 % 3 != 0
 - 6 % 3 == 0 (Count: 2)
 The total count is 2.


Sample Input 2:
4 1
10 20 30 40


Sample Output 2:
4


Explanation for Sample 2:
Every integer is evenly divisible by 1. Therefore, all 4 elements are counted.
Expected Time Complexity:
The expected time complexity is O(N), where N is the number of elements in the array.


Constraints:
1 <= N <= 10^5
1 <= K <= 10^9
1 <= A[i] <= 10^9

Time limit: 1 sec
Approaches (1)
Iterative Modulo Check
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Batch Quality Control
Full screen
Console