Given an array of length n, find the highest value that occurs the same number of times within the array. For example, given [3,8,3,2,1,3,2], 3 occurs 3 times, so the output is 3. Given [4,6,7,6,7,5,4,2,4,9,4,1,9], 4 occurs 4 times, so the output is 4.

AnswerBot
1y
Find the highest value that occurs the same number of times within an array.
Iterate through the array and count the occurrences of each value.
Store the counts in a dictionary or hash map.
Find the maxi...read more
Pritam Chowdhury
2y
private static int returnMax(int[] arr, int n){ HashMap<Integer, Integer> newHash = new HashMap<>(); int max = 0; for(int a : arr){ newHash.put(a,newHash.getOrDefault(a,0)+1); } for(Map.Entry<Integer,...read more
Help your peers!
Add answer anonymously...
Morgan Stanley Software Developer interview questions & answers
A Software Developer was asked 8mo agoQ. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 9mo agoQ. Explain the concept of a HashMap.
A Software Developer was asked Q. Why do you want to work at Morgan Stanley?
Popular interview questions of Software Developer
A Software Developer was asked 5mo agoQ1. What is abstraction?
A Software Developer was asked 8mo agoQ2. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 9mo agoQ3. Explain the concept of a HashMap.
>
Morgan Stanley Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

