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 ; Print top k elements in the heap ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void findElementsAfterDel ( int [ ] arr , int m , int [ ] del , int n , int k ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp . ContainsKey ( del [ i ] ) ) { mp [ del [ i ] ] ++ ; } else { mp . Add ( del [ i ] , 1 ) ; } } List < int > heap = new List < int > ( ) ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] -- ; if ( mp [ arr [ i ] ] == 0 ) { mp . Remove ( arr [ i ] ) ; } } else { heap . Add ( arr [ i ] ) ; } } heap . Sort ( ) ; heap . Reverse ( ) ; for ( int i = 0 ; i < k ; ++ i ) { Console . Write ( heap [ i ] + " ▁ " ) ; } } static public void Main ( ) { 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 ) ; } }