Finding the second-largest value in an array
Trust the math. When the x &gt; hi comparison fails, there is no need to test against x &lt; hi. The streamlined code should look like

    if x &gt; hi:
        ....
    elif x &gt; mid:
        ....
    else
        ....

Follow the math. In the worst case - the array sorted in the descending order - (almost) every element has go through two comparisons, making total of \$2n - 2\$, which is larger than the goal of \$n + \log{n} - 2\$
A correct approach is to arrange an elimination tournament (\$n - 1\$ comparisons to determine a champion), while keeping track of those who lose only to the champion. This makes \$log{n}\$ candidates for the second place, and \$\log{n} - 1\$ comparisons to determine the second. For the details, watch Alex Stepanov lectures starting with lecture 8, or just see the final code.

I highly recommend to watch the entire course, even if you are not interested in C++.