wap in a 2D square Matrix print the element with maximum occurrences along with the number of occurrences of that element in the matrix if more than one such element exists then print all of those element with the number of occurrences if all elements are unique then print unique.
Answers
Answered by
0
Explanation:
A simple solution is to run two loops. The outer loop picks all elements one by one. The inner loop finds the frequency of the picked element and compares it with the maximum so far. The time complexity of this solution is O(n2)
A better solution is to do the sorting. We first sort the array, then linearly traverse the array.
Similar questions