title: How do I get the max element of a std::unordered_map?
body: <p>I know how to retrieve the maximum element of a <code>std::map</code> through the use of <code>std::max_element</code>, but I am unable to achieve the same affect with a <code>std::unordered_map</code> due to the differences between the container types.</p>
  <p><strong>How can I find the maximum value in a <code>std::unordered_map</code> and return the corresponding <code>std::pair</code>?</strong></p>
  <p>My current method for doing this with a <code>std::map</code> is shown (based on <a href="https://stackoverflow.com/a/34937216/7706917">this answer</a>). I can't seem to figure out how to do the same for a <code>std::unordered_map</code>.</p>
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename KEY_T, typename VALUE_T&gt;
  std::pair&lt;KEY_T, VALUE_T&gt; findMaxValuePair(
      std::map&lt;KEY_T, VALUE_T&gt; const &amp;x)
  {
      return *std::max_element(x.begin(), x.end(),
                               [](const std::pair&lt;KEY_T, VALUE_T&gt; &amp;p1,
                                  const std::pair&lt;KEY_T, VALUE_T&gt; &amp;p2)
                               {
                                   return p1.second &lt; p2.second;
                               });
  }
  </code></pre>
  <p>When I attempt to use the above function on a <code>std::unorderd_map</code> (replacing <code>std::map</code> with <code>std::unordered_map</code>, I receive a <code>Segmentation fault (core dumped)</code>.</p>