Distributing all balls without repetition | C # program to find if its possible to distribute balls without repitiion ; function to find if its possible to distribute balls or not ; count array to count how many times each color has occurred ; increasing count of each color every time it appears ; to check if any color appears more than K times if it does we will print NO ; Driver code
using System ; public class GFG { static int MAX_CHAR = 26 ; static bool distributingBalls ( long k , long n , string str ) { int [ ] a = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ str [ i ] - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( a [ i ] > k ) return false ; return true ; } static public void Main ( ) { long n = 6 , k = 3 ; string str = " aacaab " ; if ( distributingBalls ( k , n , str ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }