Wednesday, August 30, 2017

CodeForces: New Year Transportation(500 A) Solution in Java for Beginners

 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 tutorial for if-else , in this tutorialspoint page about if-else.


New Year Transportation(500 A) Solution Link

If you are facing problems solving this , now 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 backwards. 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 in  under codeforces label.

1 comment:

  1. Hi,

    Useful post. Very well explained. Thanks for sharing.



CodeForces: Xenia and Ringroad(339B) Solution in Java for Beginners

  Xenia and Ringroad(339B) Problem Link: Since this is a beginner's problem, I suggest you try it out yourself first. Java programm...