Here, we can use hashmap and use an extra variable max_till_now that will
keep track of maximum element occured to us till now while updating.
Time complexity of solution will be O(n)
max_till_now = 0;
for ( int i = 0; i < arr.size(); i++ ) {
hashmap[arr[i]] += 1;
if ( hashmap[arr[i]] > max_till_now ) max_till_now =
hashmap[arr[i]];
}
print(max_till_now);
--
Akshat Sapra
Under Graduation(B.Tech)
IIIT-Allahabad(Amethi Campus)
*--------------------------------------*
[email protected]
[email protected]
rit20009008@ <[email protected]>iiita.ac.in
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.