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):