
Try to do it O(N) time complexity and O(1) space complexity.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘T’ lines represent the ‘T’ test cases.
The first line of each test case contains two integers ‘N’ and ‘K’, where ‘N' is the size of the array.
The second line contains ‘N’ single space-separated integers representing the elements of the array.
For each test case, return the maximum occurring integer in an array.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= 'T’ <= 50
1 <= 'N’ <= 10000
1 <= 'K' <= n
0 <= ARR[i] <= K-1 ∀ i(1,N)
Time Limit: 1sec
Approach:-The key idea is to count the frequencies of all elements of the array. For every, ‘i’ from 1 to ‘N’ count the number of times the element A[i] is appearing from ‘i’ to ‘N’.
Algorithm:
Approach:-The key idea is to store the frequencies of all the elements in a map.
Algorithm:
Approach:-The key idea is to store the frequency of A[i] at a[A[i]].To store the frequency of A[i] just do a[A[i]]+=K
Algorithm: