We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;//Youtube : The Adarsh 1MpublicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */intn;Scannersc=newScanner(System.in);n=sc.nextInt();// int min = 99999;// int [] arr = new int[n];// List<Integer> arr = new ArrayList<>();// Set<Integer> arr = new HashSet<>();TreeMap<Integer,Integer>mp=newTreeMap<>();for(inti=0;i<n;i++){intop=sc.nextInt();if(op==1){intnum=sc.nextInt();// arr.add(num);mp.put(num,mp.getOrDefault(num,0)+1);}elseif(op==2){intnum=sc.nextInt();// arr.remove(num);if(mp.get(num)>1){mp.put(num,mp.get(num)-1);}else{mp.remove(num);}}else{// int min = 9999;// for(int lol : arr){// min = Math.min(min, lol);// }System.out.println(mp.firstKey());}}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →