Practice/Amazon/Leetcode 2065. Maximum Path Quality of a Graph
CodingOptional
You are given an undirected weighted graph where each node has an associated value. Your task is to find the maximum sum of unique node values you can collect on any valid journey that:
maxTime time unitsEach edge has a travel time cost, and while you may visit nodes multiple times during your journey, each node's value contributes to your total sum at most once (only counted on the first visit).
The graph is represented by:
values: an array where values[i] is the value of node iedges: a list of undirected edges where each edge is [u, v, time] indicating nodes u and v are connected with travel time timemaxTime: the maximum time budget for your entire journeymaxTimeExample 1:
` Input: values = [0,32,10,43], edges = [[0,1,10],[1,2,15],[0,3,10]], maxTime = 49 Output: 75 Explanation: One optimal path is 0 → 3 → 0 → 1 → 0
Example 2:
Input: values = [5,10,15,20], edges = [[0,1,10],[1,2,10],[0,3,10]], maxTime = 30 Output: 25 Explanation: The path 0 → 3 → 0 takes 20 time units and collects values 5 + 20 = 25. We cannot reach node 2 and return to node 0 within the time budget.