Answer: RENAULT NISSAN TECH Hiring | Online Assessment Question | Off-Campus (2023)

Answer · Posted Jun 2026

Approach Traverse the array. Whenever nums[i] == key, increment the frequency of nums[i+1] using a HashMap. Finally, return the follower with the highest frequency. Strategy Create a frequency map. Traverse until the second-last element. If current element equals key, increment the count of the next element. Find the element with maximum frequency. Return the answer. Java Code import java.util.HashMap; import java.util.Map; class Solution { public int mostFrequent(int[] nums, int key) { Map<Integer, Integer> freq = new HashMap<>(); for (int i ...

The full answer & interview discussion are available to premium members.

Log in Create a free account