Showing:
Handle Score
@Ibrahim Nash 6560
@mb1973 5777
@Quandray 5275
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4398
@sanjay05 3762
@mantu_singh 3654
@gfgaccount 3601
@marius_valentin_dragoi 3525
Frequencies of Limited Range Array Elements
Easy Accuracy: 47.5% Submissions: 57024 Points: 2

Given an array A[] of N positive integers which can contain integers from 1 to P where elements can be repeated or can be absent from the array. Your task is to count the frequency of all elements from 1 to N.

Example 1:

Input:
N = 5
arr[] = {2, 3, 2, 3, 5}
P = 5
Output:
0 2 2 0 1
Explanation:
Counting frequencies of each array element
We have:
1 occurring 0 times.
2 occurring 2 times.
3 occurring 2 times.
4 occurring 0 times.
5 occurring 1 time.

Example 2:

Input:
N = 4
arr[] = {3,3,3,3}
P = 3
Output:
0 0 4 0
Explanation:
Counting frequencies of each array element
We have:
1 occurring 0 times.
2 occurring 0 times.
3 occurring 4 times.
4 occurring 0 times.

Complete the function frequencycount() that takes the array and n as input parameters and returns an array in place to denote the frequency count of each element from 1 to N. i,e element at index 0 should represent frequency of 1 and so on.

Expected Time Complexity: O(N logN)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 105
1 ≤ P ≤ 4*104
1 <= A[i] <= P