One by one insert elements of sorted [ ] temp and assign them values from 0 to n - 1
int val = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( umap . ContainsKey ( temp [ i ] ) ) umap [ temp [ i ] ] = val ++ ; else umap . Add ( temp [ i ] , val ++ ) ;