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 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 ) { ...
PROGRAM TO PRINT MAXIMUM NUMBER OF A'S USING GIVEN FOUR KEYS import java.io.*; class GFG { // A recursive function that returns // the optimal length string for N keystrokes static int findoptimal( int N) { // The optimal string length is N // when N is smaller than 7 if (N <= 6 ) return N; // Initialize result int max = 0 ; // TRY ALL POSSIBLE BREAK-POINTS // For any keystroke N, we need to ...
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 ...
Comments
Post a Comment