Your question is Most Frequent Element in List. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
JioCinema analytics receives a non-empty list of integer event codes from a user session. Write a function that returns the most frequent event code. If multiple codes have the same highest frequency, return the one that appears first in the list.
You should use an algorithm that runs in linear time. Do not modify the input list.
Implement most_frequent_element(nums).
nums, a non-empty list of integers.nums. If frequencies tie, return the tied integer with the lowest first-occurrence index.def most_frequent_element(nums):