Frequency count method (Time complexity analysis)