Find the k largest numbers after deleting the given elements |  ; Find k maximum element from arr [ 0. . m - 1 ] after deleting elements from del [ 0. . n - 1 ] ; Hash Map of the numbers to be deleted ; Increment the count of del [ i ] ; Initializing the largestElement ; Search if the element is present ; Decrement its frequency ; If the frequency becomes 0 , erase it from the map ; Else compare it largestElement ; Print top k elements in the heap ; Pop the top element ; Driver code
import java . io . * ; import java . util . * ; class GFG { static void findElementsAfterDel ( int arr [ ] , int m , int del [ ] , int n , int k ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp . containsKey ( del [ i ] ) ) { mp . put ( del [ i ] , mp . get ( del [ i ] ) + 1 ) ; } else { mp . put ( del [ i ] , 1 ) ; } } PriorityQueue < Integer > heap = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) - 1 ) ; if ( mp . get ( arr [ i ] ) == 0 ) { mp . remove ( arr [ i ] ) ; } } else { heap . add ( arr [ i ] ) ; } } for ( int i = 0 ; i < k ; ++ i ) { System . out . print ( heap . poll ( ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int array [ ] = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = array . length ; int del [ ] = { 12 , 56 , 5 } ; int n = del . length ; int k = 3 ; findElementsAfterDel ( array , m , del , n , k ) ; } }