FastPrepMinimum Round Trip Lengths
Problems/Minimum Round Trip Lengths

Minimum Round Trip Lengths

Microsoft logoMicrosoft● MediumOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Source note: 2026-06-23 — The official source image omitted the final answer. FastPrep inferred [60, 60, 60, 0] from the visible graph; it should be updated if the official output becomes available.

A traveling salesperson lives in a country that has road_nodes houses and m roads. The j-th road runs from house x[j] to house y[j] and has a length of t[j]. The roads are directional, meaning it is not possible to travel from house y[j] to house x[j] using the same road.

For each house x, where 1 <= x <= road_nodes, find the minimum length of a journey that starts and ends at house x. If no such path exists for a particular house x, return 0 for that house.

Note:

  • There are no multiple roads between 2 houses.
  • There can be a road that starts and ends at the same house.
  • All houses may or may not be connected.

Function

minimumRoundTripLengths(roads_nodes: int, m: int, roads_from: int[], roads_to: int[], roads_weight: int[]) → int[]

Examples

Example 1

roads_nodes = 4m = 4roads_from = [1, 2, 3, 4]roads_to = [2, 3, 1, 3]roads_weight = [14, 23, 23, 30]return = [60, 60, 60, 0]

The visible roads are 1 -> 2 with length 14, 2 -> 3 with length 23, 3 -> 1 with length 23, and 4 -> 3 with length 30.

Houses 1, 2, and 3 can each travel around the directed cycle 1 -> 2 -> 3 -> 1, whose total length is 14 + 23 + 23 = 60. House 4 has no journey that returns to house 4, so its value is 0.

More Microsoft Online Assessment questions

  • Maximum Score with Prime JumpsOA · Seen Dec 2026
  • Minimum Non-Adjacent Selection CapabilityOA · Seen Dec 2026
  • Authentication SystemOA · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
  • Cities on Shortest Delivery RoutesMathWorks · OAMathWorks interview questions
  • Shortest Path from an Encoded GraphIntuit · OAIntuit interview questions
  • Longest Distance in a Frequency-Limited NetworkBloomberg LP · OABloomberg LP interview questions
  • Find Minimum City HopsAmazon · OA
  • Minimum Stress PathWalmart · OAWalmart interview questions
  • Dijkstra Shortest Paths in a Weighted Undirected GraphVisa · OAVisa interview questions
  • Minimize Path ValuePalantir · OAPalantir interview questions
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Minimize Path ValueSalesforce · OASalesforce interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] minimumRoundTripLengths(int roads_nodes, int m, int[] roads_from, int[] roads_to, int[] roads_weight) {
      // write your code here
    }
}
Checking account…