Check if it ’ s possible to completely fill every container with same ball | C # program for above approach ; A boolean function that returns true if it 's possible  to completely fill the container else return false ; Base Case ; Backtracking ; Function to check the conditions ; Storing frequencies ; Function Call for backtracking ; Driver Code ; Given Input ; Function Call
using System ; using System . Collections . Generic ; class GFG { static bool getans ( int i , List < int > v , int [ ] q ) { if ( i == q . Length ) return true ; for ( int j = 0 ; j < v . Count ; j ++ ) { if ( v [ j ] >= q [ i ] ) { v [ j ] -= q [ i ] ; if ( getans ( i + 1 , v , q ) ) { return true ; } v [ j ] += q [ i ] ; } } return false ; } static void Check ( int [ ] c , int [ ] b ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < b . Length ; i ++ ) m [ b [ i ] ] = 0 ; for ( int i = 0 ; i < b . Length ; i ++ ) { m [ b [ i ] ] ++ ; } List < int > v = new List < int > ( ) ; foreach ( KeyValuePair < int , int > i in m ) { v . Add ( i . Value ) ; } bool check = getans ( 0 , v , c ) ; if ( check ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } public static void Main ( ) { int [ ] c = { 1 , 3 , 3 } ; int [ ] b = { 2 , 2 , 2 , 2 , 4 , 4 , 4 } ; Check ( c , b ) ; } }