New Year Transportation(500 A) Problem Link
The solution is found in the problem, so I suggest you try it by yourself.
If you need a quick reminder for while loop, check out this youtube video of newBoston.
You can find a tutorial for if-else, on this tutorialspoint page about if-else.
.
.
.
.
.
New Year Transportation(500 A) Solution Link
If you are facing problems solving this, you can come here for the solution. So after taking the necessary input, you begin from the first index (currentIndex - set to 1). Then you enter a while loop. Here on every iteration, you check whether you've reached your destination, on which case done variable will be true. If currentIndex > destination, you'll never get to destination since you can't travel backward. In this case, you just break out of the loop. The loop will terminate once you've traversed the whole array.
Finally, you check whether done is true (you've reached your destination) or false(otherwise).
Check out my other codeforces solutions under the codeforces label.
The solution is found in the problem, so I suggest you try it by yourself.
If you need a quick reminder for while loop, check out this youtube video of newBoston.
You can find a tutorial for if-else, on this tutorialspoint page about if-else.
.
.
.
.
.
New Year Transportation(500 A) Solution Link
If you are facing problems solving this, you can come here for the solution. So after taking the necessary input, you begin from the first index (currentIndex - set to 1). Then you enter a while loop. Here on every iteration, you check whether you've reached your destination, on which case done variable will be true. If currentIndex > destination, you'll never get to destination since you can't travel backward. In this case, you just break out of the loop. The loop will terminate once you've traversed the whole array.
Finally, you check whether done is true (you've reached your destination) or false(otherwise).
Check out my other codeforces solutions under the codeforces label.
Hi,
ReplyDeleteUseful post. Very well explained. Thanks for sharing.
Cheers,
http://www.flowerbrackets.com/java-if-else/