Given an array of n integers where each value represents the number of chocolates in a packet. Each packet can have a variable number of chocolates. There are m students, the task is to distribute chocolate packets such that:
Each student gets one packet.
The difference between the number of chocolates in the packet with maximum chocolates and packet with minimum chocolates given to the students is minimum.
PROGRAM TO SOLVE SUDOKU # A Utility Function to print the Grid def print_grid(arr): for i in range ( 9 ): for j in range ( 9 ): print arr[i][j], print ( 'n' ) # Function to Find the entry in # the Grid that is still not used # Searches the grid to find an # entry that is still unassigned. If # found, the reference parameters # row, col will be set the location # that is unassigned, and true is # returned. If no unassigned entries # remains, false is returned. # 'l' is a list variable that has # been passed from the solve_sudoku function # to keep track of incrementation # of Rows and Columns def find_empty_location(arr, l): for row in range ( 9 ): ...
PROGRAM TO SOLVE SUDOKU class GFG { public static boolean isSafe( int [][] board, int row, int col, int num) { // Row has the unique (row-clash) for ( int d = 0 ; d < board.length; d++) { // Check if the number we are trying to ...
PROGRAM TO FIND REPEATING NUMBERS IN AN ARRAY class MAIN { public static void main(String args[]) { int numRay[] = { 0 , 4 , 3 , 2 , 7 , 8 , 2 , 3 , 1 }; for ( int i = 0 ; i < numRay.length; i++) { numRay[numRay[i] % numRay.length] = numRay[numRay[i] % numRay.length] + numRay.length; } System.out.println( "The repeating elements are : " ); for ( int i = 0 ; i < numRay.length; i++) { if (numRay[i] >= numRay.length* 2 ) { ...
Comments
Post a Comment