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 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 PRINT ALL JUMPING NUMBERS SMALLER THAN OR EQUAL TO A GIVEN VALUE class Queue: def __init__( self ): self .lst = [] def is_empty( self ): return self .lst = = [] def enqueue( self , elem): self .lst.append(elem) def dequeue( self ): return self .lst.pop( 0 ) # Prints all jumping numbers smaller than or equal to # x starting with 'num'. It mainly does BFS starting # from 'num'. def bfs(x, num): # Create a queue and enqueue i to it q = Queue() q.enqueue(num) # Do BFS starting from 1 ...
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 ): ...
Comments
Post a Comment