Skip to content

Commit 1eef77f

Browse files
Create covid and cousin problem.txt
1 parent dfc263d commit 1eef77f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
After a dreadful lockdown, you wish to meet your friend. You live in block ‘s’. You can only move ‘f’ blocks forward or ‘b’ blocks backward. Suppose, there are ‘t’ blocks in total. If you try to move ‘f’ blocks forward and there are not sufficient blocks left then you cannot move at all. Similarly, if you try to move ‘b’ blocks backward and there are not enough blocks, this move is invalid. Now you know your friend lives in ‘d’ block so, you decide to write a program to give you minimum number of moves required to reach your friend. If you cannot reach the destination, simply print “Not reachable”.
2+
3+
Given input t, s, d, f, b (Total blocks, source, destination, forward, backward). Find the minimum number of moves required to move from ‘s’ to ‘d’ or output “Not reachable” if the solution is not possible.
4+
5+
Constraints:
6+
7+
1<=k<=10
8+
9+
0<=s,d<=t<=10000000
10+
11+
0<=f,b<=10000000
12+
13+
Input Format
14+
The first line of the input will depict ‘k’ number of testcases which follow k number of lines each of which consists t, s, d, f and b.
15+
16+
Output Format
17+
The output will be of one line consisting of minimum number of moves required to reach from s to d or return “Not reachable” if there is no way to reach d.
18+
19+
20+
21+
Sample Testcase #0
22+
Testcase Input
23+
1
24+
16 7 1 0 2
25+
Testcase Output
26+
3
27+
Explanation
28+
You can move along the path: 7-5-3-1 (backward,backward,backward)
29+
30+
So, minimum moves required will be 3.
31+
32+
Sample Testcase #1
33+
Testcase Input
34+
2
35+
36 0 3 9 0
36+
64 5 9 8 6
37+
Testcase Output
38+
Not reachable
39+
4
40+
Explanation
41+
For test case 1, Since you need to go from 0 to 3 you will first go to 9 and then since you can not move backward , so the desired destination is not reachable.
42+
43+
For test case 2, you can move along the path: 5-13-7-15-9 (forward,backward,forward,backward)
44+
45+
So, minimum moves required will be 4.

0 commit comments

Comments
 (0)