DSAAGP35 - Editorial

Problem Link - Frequency of each element in the array in Hashing

Problem Statement:

You are given an integer N and an array containing N integers. For each element in the array, you have to output its frequency in the array.

Approach:

For each element in the array:

  • Use an inner loop to go through the entire array again and count how many times the current element appears.
  • We print the frequency for each element as we process it.

Complexity:

  • Time Complexity: For each test case, we have an array of size N. The outer loop runs N times, and for each element, the inner loop also runs N times. Thus, the time complexity for each test case is O(N^2).
  • Space Complexity: O(1) No extra space needed to store output.