Kindly check my last submission

please check my latest java code and tell me why its not running all the test cases

You need to share your code via CB IDE for us to see

import java.util.; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); PriorityQueue maxHeap = new PriorityQueue<>(new Comparator() { @Override public int compare(Long o1, Long o2) { return o2.compareTo(o1); } }); int i=sc.nextInt(); int k=sc.nextInt(); //System.out.println(i); for(;i>0;i–) { int query; long y,x; query=sc.nextInt(); if(query==1) { x=sc.nextLong(); y=sc.nextLong(); maxHeap.add(xx+y*y); } else if(query ==2) { int diff=maxHeap.size()-k; while(diff>0) { maxHeap.poll(); diff–; } System.out.println(maxHeap.poll()); } } } }

hello are u there???

Can you read this code?
Shall i provide you the correct code in this format only?

i have uploaded the code

9 3 1 10 10 1 9 9 1 -8 -8 2 1 7 7 2 1 6 6 1 5 5 2

Whenever you get a query, pop k-1 elements temporarily and give the answer!

@Bhuwan-Agrawal-2362769150606526

Your code produces wrong output for below test case
4 2
1 3 3
1 4 4
2
2

The problem is where you are printing the Kth element
You are popping it and printing it while you should Not pop it and just print the element.

1 Like