Code refactor and speedup

Company: Citadel_30sep

Difficulty: medium

Problem Statement

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 (inferred -- the screenshots attached to this capture could not be retrieved, and its earlier text transcription wrote the two loops one after the other, which does not compile because edge and it are used outside the loop that declares them; the code below is taken from a legible screenshot of the same task from another sitting, where the second loop is nested inside the first) . 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