Can you tell why my code is failing test cases?

Also is the time complexity of code more than what is asked in question? How?

This is your corrected code https://ide.codingblocks.com/s/331184

I tried to submit the code but its giving TLE. Please help me out? How is my code exceeding the time limit?

this part

        if(freq[a[i]]!=0)
        {
            cout<<a[i]<<endl;
            freq[a[i]]--;
            continue;
        }

This part is incorrect. You need to iterate over i from 0 to 2 and not on a[i].