FastPrepMinimum Unreachable Warehouses
Problems/Minimum Unreachable Warehouses

Minimum Unreachable Warehouses

Visa logoVisa● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the component rule and a worked example that compares a tree with a cycle. It leaves out the function signature and numeric limits. Our version is about 97% the same as the reported question.

Special thanks: A very special thank you to an amazing fren for sharing this question with FastPrep! 🩷

There are warehouseNodes warehouses numbered from 1 through warehouseNodes. The parallel arrays warehouseFrom and warehouseTo describe undirected roads: road i connects warehouseFrom[i] and warehouseTo[i].

You must choose one direction for every road. A warehouse is reachable when at least one directed road points into it; otherwise it is unreachable.

Return the minimum possible number of unreachable warehouses after directing every road. An isolated warehouse is a one-vertex tree component and therefore contributes one unreachable warehouse.

Function

minimumUnreachableWarehouses(warehouseNodes: int, warehouseFrom: int[], warehouseTo: int[]) → int

Examples

Example 1

warehouseNodes = 6warehouseFrom = [1,2,4,5,6]warehouseTo = [2,3,5,6,4]return = 1

Warehouses 1, 2, 3 form a tree, so every orientation leaves at least one warehouse without an incoming road. Warehouses 4, 5, 6 form a cycle, whose roads can be directed in a loop. Only the tree component contributes to the answer.

Example 2

warehouseNodes = 3warehouseFrom = [1,2,3]warehouseTo = [2,3,1]return = 0

All three warehouses lie on one cycle. Direct the roads as 1 -> 2, 2 -> 3, and 3 -> 1 so every warehouse has an incoming road.

Example 3

warehouseNodes = 5warehouseFrom = []warehouseTo = []return = 5

Every isolated warehouse is its own tree component, and every one has no incoming road.

Constraints

  • 1 <= warehouseNodes <= 2 * 10^5
  • 0 <= warehouseFrom.length = warehouseTo.length <= 2 * 10^5
  • 1 <= warehouseFrom[i], warehouseTo[i] <= warehouseNodes
  • Each array pair represents one undirected road.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Visible Profiles CountMicrosoft · OAMicrosoft interview questions
  • Minimum Connection ChangesInMobi · OAInMobi interview questions
  • Fewest Pointer Changes to Make Every Node GoodIndeed · OAIndeed interview questions
  • Evaluate DivisionPlaud · ONSITE INTERVIEW
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Determine Whether Two Horses Are Genetically RelatedGoogle · ONSITE INTERVIEWGoogle interview questions
  • Most Stones Removed with Same Row or ColumnSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Count the Number of Complete ComponentsAmazon · PHONE SCREEN
  • Count Connected Components in an Undirected GraphNutanix · ONSITE INTERVIEWNutanix interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int minimumUnreachableWarehouses(int warehouseNodes, int[] warehouseFrom, int[] warehouseTo) {
      // write your code here
    }

}
Checking account…