Spectral MD interview question

graph question from leetcode (but C++ was mandatory)