Find original array from array with pairs of adjacent elements
Use indegree or DFS:
    unordered_map&lt;int, int&gt; indegree;
    unordered_map&lt;int, bool&gt; visited;
    unordered_map&lt;int, vector&lt;int&gt;&gt; mp;
    for (auto&amp; vect: adjacentPairs) {
        mp[vect[0]].push_back(vect[1]);
        mp[vect[1]].push_back(vect[0]);
        indegree[vect[0]]++;
        indegree[vect[1]]++;
    }
    int start = 0;
    for (auto&amp; in : indegree) 
        if (in.second == 1) {
            start = in.first;
            break;
        }
    }
    int n = indegree.size();
    vector&lt;int&gt; result;
    result.push_back(start);
    visited[start] = true;
    while (result.size() != n) {
        for (auto&amp; val : mp[start]) {
            if (!visited[val]) {
                result.push_back(val);
                visited[val] = true;
                start = val;
            }
        }
    }
    
    return result;