Asked inNutanix,Mts1

Reverse Edges Problem Statement

You are given a directed graph with ‘N’ nodes and ‘M’ edges, along with two specific nodes, ‘A’ and ‘B’. Your task is to find the minimum number of operations required to create at least one valid path from ‘A’ to ‘B’. The available operation involves reversing the direction of an edge.

Input:

The first input line contains an integer 'T', the number of test cases.
For each test case:
- The first line contains two space-separated integers ‘N’ (total nodes) and ‘M’ (total edges).
- The second line contains two space-separated integers ‘X’ (starting node) and ‘Y’ (ending node).
- The following ‘M’ lines each contain two space-separated integers ‘U’ and ‘V’, denoting a directed edge from ‘U’ to ‘V’.

Output:

For each test case, output the minimum number of edge reversals necessary to create a path from ‘A’ to ‘B’. Print the result for each test case on a new line.

Example:

Suppose you have a graph of 3 nodes and 3 edges, and the edges are as follows: (0, 1), (1, 2), (2, 0). To create a path from node ‘0’ (A) to node ‘2’ (B) with minimum operations, you need to reverse the edge (2, 0) to (0, 2). Therefore, the number of operations is 1.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 3000
  • 1 ≤ M ≤ min(3000, N*(N-1)/2)
  • 0 ≤ X, Y, U, V ≤ N - 1

Note: You are not required to print anything; the printing is handled by the system. Implement the function to return the correct result.

AnswerBot
4mo

The task is to find the minimum number of operations required to create a valid path from node A to node B by reversing edges in a directed graph.

  • Iterate through the graph to find the shortest path fr...read more

Help your peers!
Select
Add answer anonymously...

Nutanix Mts1 interview questions & answers

A Mts1 was asked Q. Ninja and Stack of Boxes Problem Help Ninja to create the tallest stack possible...read more
A Mts1 was asked Q. Split the String Problem Statement You are given a string str consisting of N lo...read more
A Mts1 was asked Q. Lexicographic Permutation Rank Problem Statement Given a distinct string, determ...read more

Popular interview questions of Mts1

A Mts1 was asked Q1. Ninja and Stack of Boxes Problem Help Ninja to create the tallest stack possible...read more
A Mts1 was asked Q2. Split the String Problem Statement You are given a string str consisting of N lo...read more
A Mts1 was asked Q3. Lexicographic Permutation Rank Problem Statement Given a distinct string, determ...read more
Nutanix Mts1 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits