FastPrepMinimum Route Reversals to Warehouse Zero
Problems/Minimum Route Reversals to Warehouse Zero

Minimum Route Reversals to Warehouse Zero

Myntra logoMyntra● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Myntra onsite interview for interns. The task is to find the minimum number of route reversals so that every warehouse can reach warehouse 0. The report names graph traversal that tracks edge direction. It leaves out the graph shape, the labels, the limits, and the examples. We filled those in.

Our version is about 94% the same as the reported question.

There are n warehouses labeled from 0 to n - 1 and n - 1 directed routes. Each route [from, to] permits travel from from to to.

The routes form a tree when their directions are ignored. Reverse the fewest routes so every warehouse has a directed path to warehouse 0. Return that minimum number.

Function

minRouteReversals(n: int, routes: int[][]) → int

Examples

Example 1

n = 6routes = [[0,1],[1,3],[2,3],[4,0],[4,5]]return = 3

The routes from 0 to 1, from 1 to 3, and from 4 to 5 point away from warehouse 0 in the rooted tree and must be reversed.

Example 2

n = 3routes = [[1,0],[2,0]]return = 0

Both nonzero warehouses already have a direct route to warehouse 0.

Constraints

  • 2 <= n <= 10^5.
  • routes.length == n - 1.
  • Every route contains two distinct labels in [0, n - 1].
  • The routes form one tree when directions are ignored.

More Myntra interview questions

  • Detect a Server RAM Capacity BreachONSITE INTERVIEW · Seen May 2026
  • Minimum Swaps to Group Values at Most KONSITE INTERVIEW · Seen May 2026
  • Smallest Binary-Digit MultipleONSITE INTERVIEW · Seen May 2026
  • Maximum Capped Histogram Area After One RemovalOA · Seen May 2026

Similar questions at other companies

  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
  • Course SchedulePlaud · ONSITE INTERVIEW
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Evaluate DivisionPhonePe · ONSITE INTERVIEWPhonePe interview questions
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
  • Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
  • Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions
All Myntra interview questionsSee Myntra hiring insights
Saved
class Solution {
    public int minRouteReversals(int n, int[][] routes) {
        // Return the minimum number of directed routes to reverse.
    }
}
Checking account…