We have Uber HCV(High Capacity Vehicles) are buses plying on the same routes in loops. Every route has a certain number of stops. The routes are represented as 2D array as below [[1, 2, 7], [3, 6, 7]] where route[i] shows the route that the ith HCV takes. For e.g 1st HCV route would be 1 -> 2 -> 7 -> 1 -> 2 -> 7... and so on. Find the minimum number of HCV hops needed given a source and a destination stop.
Example -
I/P :
[[1, 2, 7], [3, 6, 7]]
1(start) 6(end)
Ans - 2 ( 1-> 2 -> 7 -> 3-> 6)
Dear community please share your approaches to solve the problem.