Looking for the solution in java
Write a static method minTrucks() that accepts as parameters, total load and an array of available truck sizes and returns the minimum number of trucks required to transport the exact load. If it is not possible to transport the load, your method should return -1. f.e. minTrucks(100, {40, 50, 10, 5}) return 2 miniTrucks(9, {10, 30, 40, 5}) return -1 miniTrucks(17, {3, 20, 50}) return -1 I tried the blow, but I can not fulfill some situations. public static int minTrucks(int Load, int[] truckSizes){ int minTrucks = 0; int totLoad = Load; Arrays.sort(truckSizes); for(int i = truckSizes.length - 1; i >= 0; i--){ if(totLoad % truckSizes[i] == 0){ minTrucks += totLoad / truckSizes[i]; return minTrucks; }else if(Load % truckSizes[i] == 0){ minTrucks = Load / truckSizes[i]; return minTrucks; }else{ minTrucks += totLoad / truckSizes[i]; totLoad %= truckSizes[i]; } } return -1; }