Hostel visit -heap challange

both testcase gives wrong answer

@kumar_07
Use long long int for your code instead of int as the values can easily exceed the range of int. Moreover you should not push all your values into the heap but compare each value with the top element of the heap before pushing it. That is , the flow should be something like this :

        if(pq.size() < k){
            pq.push(ans);
        }
        else if(ans < pq.top()){
            pq.pop();
            pq.push(ans);
        }

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.