← Morgan Stanley questions
CodingReported in a candidate post, Aug 2020

Connected components sorted by component sum and node count

Filed under Morgan Stanley

Given a graph where nodes have values, identify all connected components. Return them sorted by the sum of node values (descending), then by the number of nodes (descending).

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Morgan Stanley questions

Collected from public candidate posts and coding forums. Updated Nov 2026.