Shortest Path in Ninjaland
Ninjaland consists of ‘N’ states and ‘M’ paths. Each path connecting two states can either be a normal path or a special path, each with its unique length. Your task is to find the shortest distance between two given states such that the path includes at most one special path.
Example:
Input:
N = 3, M = 2
Paths = [[1, 2, 2, 3], [2, 3, 4, 2]]
X = 1, Y = 3
Output:
4
Explanation:
You can travel from state 1 to state 2 via the normal path (length 2) and from state 2 to state 3 via the special path (length 2), totaling 4.
Constraints:
- 1 <= T <= 10
- 1 <= N < 103
- N-1 <= M <= 103
- 1 <= A,B,X,Y <= N
- 1 <= W1,W2 <= 106
- Time Limit: 1 sec
Note:
All paths are directed with no self-loops, and all states are inter-connected. Multiple paths can exist between two states, but at least one path will always exist between the two given states.

AnswerBot
4mo
Find the shortest distance between two states in Ninjaland with at most one special path.
Use Dijkstra's algorithm to find the shortest path between two states.
Keep track of the shortest path with at m...read more
Help your peers!
Add answer anonymously...
Optum Global Solutions Associate Software Engineer interview questions & answers
An Associate Software Engineer was asked 12mo agoQ. How will you approach a problem which you are completely unaware of?
An Associate Software Engineer was asked Q. Given a string s, reverse the order of words in the string.
An Associate Software Engineer was asked Q. Given the head of a singly linked list, return the middle node of the linked lis...read more
Popular interview questions of Associate Software Engineer
An Associate Software Engineer was asked 11mo agoQ1. How will you approach a problem which you are completely unaware of?
An Associate Software Engineer was asked Q2. Given a string s, reverse the order of words in the string.
An Associate Software Engineer was asked Q3. Given the head of a singly linked list, return the middle node of the linked lis...read more
>
Optum Global Solutions Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

