Header Ads Widget

Car Race | TCS NQT Solution

 In a premier championship series of sports car racing, initially, the 1st car is ahead of the 2nd car by X metres. After that, every second, the 1st car moves ahead by n1 metres and the 2nd can move ahead by n2 metres (in the same direction).

The task is to print the number of seconds after which the 2nd car crosses the 1st car. If it is impossible to do so, then print -1

Input

The first line of the test case contains 3 integers separated by space n1,n2 and X.

Output

For each test case print, the time taken by car2 to overtake car1 or print -1 is car2 never able to move ahead of car1.

Examples

input
3 4 1
output
2
input
5 4 1
output
-1
input
2 12 15
output
2

Note

Taking 1st test case as an example :

Initially, the 1st car is ahead by 1 metre.

After the 1st second, the 1st and 2nd cars are at the same place.

After the 2nd second, the 2 car moves ahead of the 1st car by 1 metres.

Code(C++):-

#include <iostream>
using namespace std;

int main()
{
int n1,n2,x;
cin>>n1>>n2>>x;
if(n1>=n2)
cout<<-1;
else
{
int t=x/(n2-n1)+1;
cout<<t;
}
return 0;
}


Code(Python):-

n1,n2,x=map(int,input().split())
if(n1>=n2):
print("-1")
else:
n2=n2-n1
t=(x//n2)+1
print(t)


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments