Modify Graph Edge Weights | Dijkstra's Algorithm IN JAVA | Leetcode 2699 | MUST DO MAANG QUESTIONS
Code Thoughts Code Thoughts
1.31K subscribers
84 views
5

 Published On Aug 30, 2024

Question link:- https://leetcode.com/problems/modify-...

Dijkstra's Algorithm, Must watch :-    • Dijkstra Algorithm In Hindi | Single ...  

we are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges. indicates that there is an edge between nodes ai and bi with weight w.

Some edges have a weight of -1

Your task is to modify all edges with a weight of -1 by assigning them positive integer values in the range [1, 2 * 109] so that the shortest distance between the nodes source and destination becomes equal to an integer target. If there are multiple modifications that make the shortest distance between source and destination equal to target, any of them will be considered correct.

My Approach is simple, i initially finding the min weight distance between source and destination without negative edges, then if weight is smaller than target i would return empty array else i would keep on adding negative edges with positive values starting from 1 and keep on checking Dijkstra algorithm min distance if we get distance equal to target return edges else return empty array.


counting Sort :-
   • Sort an Array in O(n) |Counting Sort ...  

DSA Algorithms :-
   • Topological sorting in Hindi | Topolo...  
Design HLD:-
   • Design E-commerce website | Design Am...  

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish

show more

Share/Embed