## Basic Concepts of Time and Distance

Most of the aptitude questions on time and distance can be solved if you know the basic correlation between speed, time and distance which you have learnt in your high school class.

Relation between time, distance and speed: Speed is distance covered by a moving object in unit time.
• $Speed=Distance CoveredTime taken$
• Ratio of the varying components when other is constant: Consider 2 objects A and B having speed $Sa$,$Sb$. Let the distance travelled by them are $Da$ and $Db$ respectively and time taken to cover these distances be $Ta$ and $Tb$ respectively.
Let's see the relation between time, distance and speed when one of them is kept constant
1. When speed is constant distance covered by the object is directly proportional to the time taken.
ie; If $Sa=Sb$, then $DaDb=TaTb$
2. When time is constant speed is directly proportional to the distance travelled.
ie; If $Ta=Tb$, then $SaSb=DaDb$
3. When distance is constant speed is inversely proportional to the time taken ie if speed increases then time taken to cover the distance decreases.
ie; If $Da=Db$, then $SaSb=TbTa$
• We know that when distance travelled is constant, speed of the object is inversely proportional to time taken.
1. If the speeds given are in Harmonic progression or HP then the corresponding time taken will be in Arithmetic progression or AP
2. If the speeds given are in AP then the corresponding time taken is in HP
• Unit conversion:While answering multiple choice time and dinstance problems in quantitative aptitude test, double check the units of values given. It could be in m/s or km/h. You can use the following formula to convert from one unit to other
1. $x$ km/hr = $x518$ m/s
2. $x$ m/s = $x185$ km/hr

## Average Speed

Average speed is always equal to total distance travelled to total time taken to travel that distance.
$Average speed=Total distanceTotal time$
• Distance Constant
If distance travelled for each part of the journey, ie $d1=d2=d3=...=dn=d$, then average speed of the object is Harmonic Mean of speeds.
Let each distance be covered with speeds $s1,s2,...sn$ in $t1,t2,...tn$ times respectively.
Then $t1=ds1$$t2=ds2$, … $tn=dsn$
$Average Speed=d+d+d+…ntimes(ds1)+(ds2)+(ds3)+...(dsn)$
$Average Speed=n(1s1)+(1s2)+…+(1sn)$
• Time Constant
If time taken to travel each part of the journey, ie $t1=t2=t3=…tn=t$, then average speed of the object is Arithmetic Mean of speeds
Let distance of parts of the journey be $d1,d2,d3,...dn$ and let them be covered with speed $s1,s2,s3,...sn$respectively.
Then $d1=s1t$$d2=s2t$$d3=s3t$, ... $dn=snt$
$Average Speed=s1t+s2t+...+sntt+t+...+ntimes$
$Average Speed=s1+s2+s3+...+snn$

## Relative Speed

• If two objects are moving in same direction with speeds a and b then their relative speed is $|a-b|$
• If two objects are moving is opposite direction with speeds a and b then their relative speed is $(a+b)$

## Important shortcuts to solve time and distance problems quickly

Using the shortcuts provided below, you can solve the aptitude problems on time and distance quickly
1. Given a person covers a distance with speed a km/hr and further covers same distance with speed b km/hr, then the average speed of the person is:
$Average speed=Total distance travelledTotal time taken$
Let the distance covered be d km
Given d km be covered with speed a km/hr in time $t1$ hour => $t1=da$
Given next d km be covered with speed b km/hr in time $t2$ hour => $t2=db$
$Average speed=2dda+db$
$Average speed=2aba+b$
Shortcut: As discussed in "Basic Concepts" section, average speed is the HM (Harmonic Mean) of speeds a & b
2. Given a person covers a certain distance d km with speed a km/hr and returns back to the starting point with speed b km/hr.
• If the total time taken for the whole journey is given as T hours, then to find d:
We know $average speed=total distance travelledtotal time taken$
Also $average speed=2aba+b$
=> $2aba+b=2dT$
$d=T(aba+b)$ km
• If the difference between the individual time taken are given that is, if distance d is covered in $t1$ hours with speed a km/hr and same distance is covered with speed b km/hr in $t2$ hours, then to find d:
$Difference between individual time=t1–t2(ift1>t2)$
Also $t1=da$ and $t2=db$
So $t1–t2=da–db$
$d=(t1–t2)(abb–a)$ km
3. If a person covers $pth$ part of a distance at x km/hr, $qth$ part of the distance at y km/hr, $rth$ part of the distance at zkm/hr, then average speed is
$Average speed=1(px)+(qy)+(rz)$
4. Two persons A and B start at the same time from two points P and Q at the same time towards each other. They meet at a point R and A takes $ta$ time to reach Q and B takes $tb$ time to reach B. If speed of A and B are $Sa$ and $Sb$ respectively.
• Then $SaSb$ is: Let $PQ=d$ and also let $PR=l$ => $RQ=d–l$
Time taken by A to cover PR is same as time taken by B to cover QR.
We know that when time is constant, speed is directly proportional to distance covered.
So, $SaSb=PRQR=ld–l$
Also, B takes $tb$ time to cover PR => $PR=Sbtb$ => $l=Sbtb$
A takes ta time to cover RQ => $RQ=Sata$ => $d–l=Sata$
Substituting these values in above equation, we get $SaSb=SbtbSata$
=> $SaSb=tbta$
• Then time taken by A and B to meet at point R is:
We know $t=PRSa$
From previous analysis we also know $PR=Sbtb$ and $SaSb=tbta$
So $t=SbtbSa=tbtbta$
Thus $t=tatb$
• Both equations are valid even if A and B start at 2 different times from P and Q towards each other where A takes $ta$ time to reach R and B takes $tb$ time to reach R. After meeting at R they take the same time $t$ to reach Q and P respectively
5. Two persons A and B start at the same time from two points P and Q at the same time towards each other with speeds $S1$ and $S2$ respectively. They reach their respective destinations and reverse their directions. They continue this to and fro motion. If $S1$ > $S2$ and $S1$ < $2S2$ and D is the initial distance separating them, then,
• $Total distance covered till nth meeting=(2n-1)D$
• $Time taken by them to meet for the nth time=(2n-1)DS1+S2$

$=DS1+S2$
After meeting, they continue to Q and P respectively. When they reach their destinations, they have together covered 2D distance.
Then they reverse directions. By the time they meet for second time, they will have covered 3D distance. Total distance covered by A and B for their 3rd meeting is 5D.
With this logic, $by nth meeting, they will have covered a total distance=(2n-1)D$.
$Time taken by them to meet for the nth time=(2n-1)DS1+S2$
• Point of meeting when they meet for the nth time
1. Distance covered by A till nth meeting = Speed of A * Time taken by A till nth meeting $=S1(2n-1)DS1+S2$
2. Divide distance obtained in step 1 by 2D, if value > 2D.
3. Remainder obtained in step 2 will give you the distance of meeting point from P
When you learn time and distance, you should keep in mind to cover following sections:
• Time and distance
• Relative speed and average speed
• Trains
• Boats and streams
• Races
• Clocks
All these are just different variations of that one simple formula speed = distance / time.

### C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
aaaa nnnn
Explanation

### Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
1. Booking
2. Availability checking
3. Cancellation
4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

My Solution :