diff --git a/KLargestElements.java b/KLargestElements.java new file mode 100644 index 0000000..9cad786 --- /dev/null +++ b/KLargestElements.java @@ -0,0 +1,31 @@ +import java.util.PriorityQueue; +import java.util.Scanner; + +public class KLargestElements { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] arr = new int[n]; + for(int i=0; i pq = new PriorityQueue<>(); + for (int i =0;i< arr.length;i++){ + if (i pq.peek()){ + pq.remove(); + pq.add(arr[i]); + } + } + } + + while (pq.size()>0){ + System.out.println(pq.remove()); + } + } +}