Back to problems

Maximize Edge Sum in Graph

Algorithm · Microsoft · Medium

You are given an undirected graph made up of n nodes, numbered from 0 to n - 1. The graph is supplied as the array edges, where an element $$[a_i, b_i]$$ describes an edge joining node $$a_i$$ and node $$b_i$$. Your task is to place a permutation of the integers $$1, 2, \dots, n$$ onto the nodes, so that every node gets a distinct label; write $$label(u)$$ for the label given to node u. For an edge joining nodes u and v, the value of that edge is $$label(u) + label(v)$$. Out…

Loading the rest of the question…