Find K for every Array element such that at least K prefixes are â ‰¥ K | C # program for the above approach ; Function to find the K - value for every index in the array ; Multiset to store the array in the form of red - black tree ; Iterating over the array ; Inserting the current value in the multiset ; Condition to check if the smallest value in the set is less than it 's size ; Erase the smallest value ; h - index value will be the size of the multiset ; Driver code ; Array ; Size of the array ; Function call
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void print_h_index ( int [ ] arr , int N ) { ArrayList ms = new ArrayList ( ) ; for ( int i = 0 ; i < N ; i ++ ) { ms . Add ( arr [ i ] ) ; int t = int . MaxValue ; foreach ( int x in ms ) { if ( x < t ) { t = x ; } } if ( t < ms . Count ) { ms . Remove ( t ) ; } Console . Write ( ms . Count + " ▁ " ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 9 , 10 , 7 , 5 , 0 , 10 , 2 , 0 } ; int N = arr . Length ; print_h_index ( arr , N ) ; } }