can u plz mark any error here ??
its not running…
Top k most freq element in stream
According to your approach, many instances of the same number are begin created in the priority_queue.
Suppose the sequence is 5 5 5 5 5 5.
Then the priority_queue contains {5, 1}, {5, 2}, , , {5, 5} which is not at all correct. Please read the question again.
Refer to this code once and you will be able to understand.
If my answer was able to clear your doubt, please mark the doubt as resolved.
Hi @Ashu1318 bro,
Your Error: it should be ‘&&’ not ‘||’
So, it’s like:
while(!pq.empty() && k--)
yeah now its running but output is not same can u plz make more changes int this or tell me some steps i missed??
Use min Heap…
can u explain how min heap works here??
You should use min Heap anyway because the question tells that if frequency are same then you should print in increasing order. So this is the solution of half of the problem.
This is the modified code but not efficient:
its bit long and complex code can u plz share short and efficiant code for this one ??
You can see this one:
Explanation:
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
sorry sir for response i was little busy
can u plz explain this method on call as
Please tell me the issue you want me to resolve.