Highest Frequency TLE

Got TLE in 2 cases

Your code is already O(n). Try to submit your code on hackerblocks and then check.
Or submit this code and check

IT worked well. Thank you.