I'm using python language.
say the list = [a, b, a, e, g, a, b]
so, the output should be: a, b
What I have tried:
I have tried this algorithm:
1- make a dictionary and put the characters without repeating. #{a, b, e, g}
2- list = []
3- for each character in the dictionary:
if the character doesn't exist in the list:
count the character and append it to the list
4- sort the list, with reverse
5- print the first two characters
Will it be O(n)?
and if not, how will I make an algorithm that solve this problem with the possible less time complexity?