Any programmer geeks to help?
Any geek programmer around here to help. Either in java or C#?
Will post the problem statement if any programmer responds to the thread. This is a take home interview question.
Last edited: 15-Apr-14 08:53 AM
post it. sajha is full of programmers.
I ain't the one though. :)
Have you heard of Cunningham's Law ?
You probably might try a different approach and will be surprised by the result.
YOu are asking as if you are doing us a favor. Do you plan to be a programmer when you graduate? If the answer is yes, then you should do it yourself. If no, then post the question, somebody might help;.
प्रश्नै नगरी उत्तर खोज्ने हरु नि हुदो रहेछ | क्या गजब छ बा |
I am in software development profession for quite a while.
When I interview programmers I give this question as a part of screening. It might be helpful to new programmers who are seeking placement. Thanks for good thoughts.
Here you go.
When a car breaks, it is sent to the car repair shop, which is capable of repairing at most CountPerDay cars per day. Given a record of the number of cars that arrive at the shop each morning, your task is to determine how many days the shop must operate to repair all the cars, not counting any days the shop spends entirely workless.
For example, suppose the shop is capable of repairing at most 8 cars per day, and over a stretch of 5 days, it receives 10, 0, 0, 4, and 20 cars, respectively. The shop would operate on days 1 and 2, sit idle on day 3, and operate again on days 4 through 7. In total, the shop would operate for 6 days to repair all the cars.
Write a class CarRepairs containing a method GetDays that takes a sequence of In-coming counts InComing(of type int[]) and an int CountPerDay, and calculates the number of days of operation.
Definition
Class: CarRepairs
Method: GetDays
Parameters: int[], int
Method signature: int GetDays (int[] InComing, int CountPerDay )
Returns: int
Conditions:
-InComing contains between 1 and 20 elements, inclusive.
-Each element of InComing is between 0 and 100, inclusive.
-CountPerDay is between 1 and 50, inclusive.
Last edited: 15-Apr-14 11:04 AM
oiee Nas(ey), tero jagir khatrama xa hai keta. :)
foreach (var car in InComing)
{
numOfCars += car;
}
--------------------------------
analysis as according to your soln:
int[] incoming = { 10, 0, 0, 4, 20 };
numOfCars = 34;
numOfCars/countPerDay = Math.Ceiling will give you 5
but actual answer should be 6.
:)
plz redo it without dreaming about priyanka and re-post it.
That'st your assignment. :)
Last edited: 01-May-14 02:24 PM
Last edited: 01-May-14 02:25 PM
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;
}
}
नाश ब्रो ले त सबै आएको कार जोडेर भाग मात्र गर्या छ त कोडमा | यान्सर औछ त ? येत्ति सिम्प्ल त हुन नपर्ने सोलुशन | अनि के के सिलिङ्ग फिलिंग लगाछ | सिलिङ्गमा त पंखा पो झुण्ड्याउनु पर्छ |
ल यो इन्पुटले के दिन्छ त्यो कोड मा : १७,०,०,५,१३,८,१०,१२,४ . दिनमा ८ ओटाको दरले |
यसको जवाफ मेरो विचार मा १० हुन्छ |
I've a solution here. Just a skeleton code for business logic portion not the whole code.
Please advise a condition where and when this won't work. I'll try to modify the code accordingly. But for the scenario dd has posted, this should work like a charm.
int remainingCar = 0
int day = 0;
int i = 0;
for(int car: carArr) {
i++;
totalCarWaitingForRepair = car + remainingCar;
if(totalCarWaitingForRepair >= 8) {
day += totalCarWaitingForRepair/8;
remainingCar = totalCarWaitingForRepair%8;
}
else if (totalCarWaitingForRepair > 0) {
day++;
remainingCar = 0;
}
if(i == carArr.size() && remainingCar > 0) {
day++;
}
}
totalCarWaitingForRepair%8; fails when there are more than 16 cars.
sorry 15.
I didnt check other lines but that line should be
remainingCar = (totalCarWaitingForRepair-8)<0?0:(totalCarWaitingForRepair-8);
Why should it fail when there are more than 15 cars. At that time, day will come as more than 1. So when there are 19 cars, day will be 2 and remaining car will be 3.
Why should it fail when there are more than 15 cars. At that time, day will come as more than 1. So when there are 19 cars, day will be 2 and remaining car will be 3.
Why should it fail when there are more than 15 cars. At that time, day will come as more than 1. So when there are 19 cars, day will be 2 and remaining car will be 3.
Why should it fail when there are more than 15 cars. At that time, day will come as more than 1. So when there are 19 cars, day will be 2 and remaining car will be 3.
Why should it fail when there are more than 15 cars. At that time, day will come as more than 1. So when there are 19 cars, day will be 2 and remaining car will be 3.
Sorry guys. Hit submit multiple times thinking that the button didn't work. So are there multiple entries. Coudn't delete the duplicates from mobile version.
cant figure out until u paste the code..
Please log in to reply to this post
You can also log in using your Facebook