It is giving correct result on sample test case. Cant figure out why its not working. I am maintaining hashmap for freq of every number. The i am inserting contents of map into k size min heap. I compare with top element and if freq is greater then i insert and then remove element from top to maintain size k. But i have to print in reverse order so i empty queue into a stack and keep popping from stack and printing it.
Wrong ans in Top k most freq element
you have to print a new line after each testcase
use cout<<endl;
if you want to ask something about this feel free to ask
i hope this helps
if yes show your response with
and donβt forgot to mark doubt as resolved
1 Like