I was doing the coding challenges on Codefights, sponsored by Uber and there was a problem that I was unable to solve. For the question, you can look here http://codepen.io/ducminhn/pen/JYmrmE.
I believe that this problem is related with Dynamic Programming, so I tagged this problem as Dynamic programming, but I am still learning Java, so please inform me if I am wrong. This is what I have so far, and I believe that my logic may not be correct inside the nested for loop. If anyone could please review my code and fix it for me.
Thanks in advance,
boolean parkingSpot(int[] carDimensions, int[][] parkingLot, int[] luckySpot) {
int carx = carDimensions[0];
int cary = carDimensions[1];
boolean result = false;
for(int l=0;l<parkingLot.length;l++){
for(int k=0;k<parkingLot.length;k++){
if(l == luckySpot[0]){
for(int i=luckySpot[0];i<carx;i++){
if(k== luckySpot[1]){
for(int j= luckySpot[1];j<cary;j++){
if(parkingLot[i][j] != 0){
result = false;
}
}
}
}
}
}
}
return true;
}