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
2houses. - There can be a road that starts and ends at the same house.
- All houses may or may not be connected.
roads_nodes = 4 m = 4 roads_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.
This output was added by FastPrep to make the problem uploadable because the official source image does not show the final answer. Based on the visible graph, the inferred output is [60, 60, 60, 0]. If you know the official output, please let us know, and we will update it once an official source is available. Thank you! 🌷 (06-23-2026)
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Distinct Number Line MovesOA · Seen Oct 2025
- Programmer StringsOA · Seen Aug 2025
- Get Minimum TimeSeen Jun 2025
public int[] minimumRoundTripLengths(int roads_nodes, int m, int[] roads_from, int[] roads_to, int[] roads_weight) {
// write your code here
}