Count ways to distribute exactly one coin to each worker | C # program for the above approach ; Function to find number of way to distribute coins giving exactly one coin to each person ; Sort the given arrays ; Start from bigger salary ; Increment the amount ; Reduce amount of valid coins by one each time ; Return the result ; Driver code ; Given two arrays ; Function Call
using System ; using System . Collections ; class GFG { static int MOD = 1000000007 ; static int solve ( ArrayList values , ArrayList salary ) { int ret = 1 ; int amt = 0 ; values . Sort ( ) ; salary . Sort ( ) ; while ( salary . Count > 0 ) { while ( values . Count > 0 && ( int ) values [ values . Count - 1 ] >= ( int ) salary [ salary . Count - 1 ] ) { amt ++ ; values . RemoveAt ( values . Count - 1 ) ; } if ( amt == 0 ) return 0 ; ret *= amt -- ; ret %= MOD ; salary . RemoveAt ( salary . Count - 1 ) ; } return ret ; } public static void Main ( string [ ] args ) { ArrayList values = new ArrayList ( ) ; values . Add ( 1 ) ; values . Add ( 2 ) ; ArrayList salary = new ArrayList ( ) ; salary . Add ( 2 ) ; Console . Write ( solve ( values , salary ) ) ; } }