Posted by: gairamailo May 1, 2014
Any programmer geeks to help?
Login in to Rate this Post:     0       ?        
I hope I understood the reqs coz I am very bad at that. Tested with few sample inputs and seems to be fine.

public class CarRepairs {

public static void main(String[] args) {
CarRepairs theRepairs = new CarRepairs();

int theDays = theRepairs.GetDays(new int[]{10,0,0,4,20} , 8);
System.out.println("10,0,0,4,20 With 8 Cars/day.This should take 6 days :" +theDays);

theDays = theRepairs.GetDays(new int[]{17,0,0,5,13,8,10,12,4} , 8);
System.out.println("17,0,0,5,13,8,10,12,4 With 8 Cars/day.This should take 10 days :" +theDays);

theDays = theRepairs.GetDays(new int[]{5,5,1,0,0,4} , 3);
System.out.println("5,5,1,0,0,4 With 3 Cars/day.This should take 6 days :" +theDays);



}

int GetDays (int[] InComing, int CountPerDay )
{
if(CountPerDay == 0)
return 0;
int lagneDin = 0 ;
int baakiRahekoGadi = 0;
for(int numOfCarsPerDay : InComing)
{
int totalCarsToWork = numOfCarsPerDay+baakiRahekoGadi;
System.out.println("Ajako car "+numOfCarsPerDay);
System.out.println("Baaki raheko gadi "+baakiRahekoGadi);
baakiRahekoGadi = 0;
System.out.println("Totals Car to work "+totalCarsToWork);
System.out.println("------------------------ ");
if(totalCarsToWork != 0)
{

if(totalCarsToWork < CountPerDay)
{
++lagneDin;
baakiRahekoGadi = 0 ;
}
else
{
int carsSetPerDay = totalCarsToWork / CountPerDay;
lagneDin+= carsSetPerDay;
baakiRahekoGadi += (totalCarsToWork % CountPerDay);
}
}


System.out.println("Lagne din "+lagneDin);
System.out.println("---------");
}
int additionalDays = 0;
System.out.println("Last ma baki "+baakiRahekoGadi);
if(baakiRahekoGadi > 0)
additionalDays = baakiRahekoGadi / CountPerDay;
lagneDin += additionalDays;
if(baakiRahekoGadi%CountPerDay > 0)
++lagneDin;

return lagneDin;
}

}

Read Full Discussion Thread for this article