Please provide hint for this problem ( see description )

https://mycode.prepbytes.com/problems/arrays/CURRENTFLOW

You need to handle two cases.

  • Both start and end points are on the same wire. In that case the current can travel from start to end on that wire itself, OR it can switch to the other wire at the upcoming junction (use binary search (lower bound) to find the junction just after the start point) of both the wires, and then again switches to the other wire at the last junction before the end point. Minimum of these two values is the answer.
  • Points lie on different wires. In that case the current can travel on the first wire and switch to the other wire at the last junction before the end point, OR it can switch to the other wire at the junction just after the starting point. Again, minimum of these two values is the answer.

Don’t forget to add T each time you transition from one wire to another.

1 Like

Thanks a lot :smile: