Marks :50
: 3 | : 0
You are given a graph consisting of $$$n$$$ nodes (numbered from 1 to $$$n$$$) and $$$m$$$ edges. You need to first calculate the difference between the maximum numbered and minimum numbered node in each connected component. Then you need to answer the maximum of these differences across all connected components.
The first line of input consists of two space separated integers $$$n$$$ $$$(1 \leq n \leq 10^5)$$$ and $$$m$$$ $$$(1 \leq m \leq 10^5)$$$. The next $$$m$$$ lines each consist of 2 space separated integers, $$$u$$$ and $$$v$$$, which denote that there is an edge between the nodes $$$u$$$ and $$$v$$$.
The output consists of a single integer - the maximum difference across all connected components.
6 4 1 3 3 5 5 2 2 4
4
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.