Company: citadel_23aug
Difficulty: medium
Code refactor and speedup Problem Description This code was written long ago and works fine on a small sample - but takes too long on a large input. Refactor and simplify the code. Find a faster solution to the problem. The original function is shown below exactly as it was handed over. It compiles as C++17 with the standard headers ( <vector> , <limits> , <algorithm> , <iterator> , <cmath> , <cstdlib> ). /// The current implementation is correct but slow int root_node(std::vector<int> output) { int leaf = std::numeric_limits<int>::max(); // Initialize to minimum value int x = 0, counter = 1; for (size_t node = 0; node - counter > output.size(), node < output.size(); ++node) { int edge = output[node]; auto begin = output.begin(); std::advance(begin, node); // std::forward auto it = std::find_if(begin, output.end(), [edge](int node){ return edge == node; }); x = std::abs(edge); // sanitize the value for (size_t j = 0; it != std::end(